Oga87 Posted August 28, 2024 Posted August 28, 2024 Hello Dear AutoCAD specialists! The code below “excel-vba” allows you to update attribute values. The problem is that if this attribute is “multiline”, such properties as, for example, compression are reset: it was 0,8 - after updating -1. (as well as slope, etc.). Could you please tell me how to fix the code so that after updating multiline attributes, such properties are preserved? n_at = 0 varAttributes = blockObj.GetAttributes For r_a_n = 8 To Col_N1 For n_at = LBound(varAttributes) To UBound(varAttributes) If varAttributes(n_at).TagString = Cells(6, r_a_n).Value Then varAttributes(n_at).TextString = ActiveCell.Offset(0, r_a_n - 6).Value Next n_at Next r_a_n Quote
BIGAL Posted August 29, 2024 Posted August 29, 2024 You may need to look at the textstring sometimes it can be Line1line2 or it can be line1\\Pline2 or maybe Line1\nline2 when replacing the string, need the add a line break, Sorry dont do VBA just dabble at edges. Quote
Oga87 Posted August 29, 2024 Author Posted August 29, 2024 Even with one line of a multi-line attribute, compression is reset. Quote
SLW210 Posted August 29, 2024 Posted August 29, 2024 Any reason your not doing this from AutoCAD? Plenty of LISP, VBA, etc. out there for that already, though I never really dabbled with altering Multiline Attributes. From what I see, Multiline Attributes have to be handled different than Single Line Attributes. Start with this, I will look more when I can spare some time at work. Let me know if this is getting closer. varAttributes = blockObj.GetAttributes For r_a_n = 8 To Col_N1 For n_at = LBound(varAttributes) To UBound(varAttributes) tagName = Cells(6, r_a_n).Value newValue = ActiveCell.Offset(0, r_a_n - 6).Value If varAttributes(n_at).TagString = tagName Then varAttributes(n_at).TextString = newValue If varAttributes(n_at).TextString <> newValue Then varAttributes(n_at).TextString = newValue End If End If Next n_at Next r_a_n You might also check out this post... steven-g probably has some more code around, he mostly used LT and used Excel a lot to handle AutoCAD LT. Quote
Oga87 Posted August 29, 2024 Author Posted August 29, 2024 Thanks, this code also resets the specified compression. Perhaps the compression should be remembered (as a property) and then returned. Quote
Danielm103 Posted September 5, 2024 Posted September 5, 2024 You probably need to save the previous string to get the mtext control strings, append these to the new value https://adndevblog.typepad.com/autocad/2017/09/dissecting-mtext-format-codes.html Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.