Multileader text lines to Block Attribute

Multileader text lines to Block Attribute

jr_olmos23
Enthusiast Enthusiast
345 Views
4 Replies
Message 1 of 5

Multileader text lines to Block Attribute

jr_olmos23
Enthusiast
Enthusiast

Is it possible to make a LISP that takes the 1st, 2nd, and 3rd lines of text from a multileader an updates the respective attribute tags on a block. I have attached an example. From the 3rd line of the multileader the text "Part#: " would have to be ignored of course, and also, some piece names will have long names that will appear as if they are on the 2nd/3rd line of the multileader but in reality it's the same line. By line I mean when you're typing and then press "enter" so that even if I extend the text width the lines remain individual.

0 Likes
Accepted solutions (1)
346 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor
Accepted solution

Try this

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/multileader-text-lines-to-block-attribute/td-p/13300068

(defun c:wow ( / ent txt txtstr atts)

; tab 9 space 32 (chr 32) comma 44 semicolum 59 slash / 47 ~ 126

; thanks to Lee-mac for this defun
(defun csv->lst126 ( str / pos )
(if (setq pos (vl-string-position 126 str))
    (cons (substr str 1 pos) (csv->lst126 (substr str (+ pos 2))))
    (list str)
    )
)

(setq ent (entget (car (nentsel "\nPick mleader text "))))
(setq txt (cdr (assoc 304 ent)))
(repeat 3
(setq txt (vl-string-subst "~" "\\\P"  txt))
)
(setq txtstr (csv->lst126 txt))

(setq obj (vlax-ename->vla-object (car (entsel "\nPick block object "))))
(setq atts (vlax-invoke obj 'Getattributes))
(vlax-put (nth 4 atts) 'textstring (nth 0 txtstr))
(vlax-put (nth 5 atts) 'textstring (nth 1 txtstr))
(vlax-put (nth 6 atts) 'textstring (nth 2 txtstr))
(vlax-put (nth 7 atts) 'textstring (nth 3 txtstr))

(princ)
)
(c:wow)
0 Likes
Message 3 of 5

jr_olmos23
Enthusiast
Enthusiast

Okay this seems to work as I expected. The only thing is that it also fills in the "C/F: " attribute with the remaining text after the 3rd line, and the part number also pulls in the "Part#: " portion of the text. If it can be done to only pull in the X.X.X portion of the "Part#: X.X.X" that would be great. 

0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

I noticed that Part Part was occurring, so a simple fix if you have the Part in the text all the time is remove the default text "Part" in the block. Do you ever have like "Part 123" or just "123" in which case Part needs to be removed or added, rather than removed. 

 

You could do a check of (nth 3 txtstr) using "wcmatch" function to see if it contains "Part", a good time to learn lisp.

0 Likes
Message 5 of 5

jr_olmos23
Enthusiast
Enthusiast

Okay yeah didn't think of removing the "Part" from the block itself. The multileader will always have the "Part#: X.X.X " so it can bring it in complete. Thanks man!

0 Likes