How would I modify this lisp routine to add elevations to the points created. I would need the point z value set to the multileader content field. Attaching example file as well.
(defun LM:mleadervertices ( ent )
(mapcar '(lambda ( x ) (massoc 10 x))
(massoc "LEADER_LINE{"
(cdr
(assoc "LEADER{"
(cdr
(assoc "CONTEXT_DATA{"
(parsedxfdata (entget ent))
)
)
)
)
)
)
)
(defun massoc ( k l )
(mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= k (car x))) l))
)
(defun parsedxfdata ( l / foo )
(defun foo ( / x )
(setq x (car l)
l (cdr l)
)
(cond
( (or (null x) (= "}" (cdr x)))
nil
)
( (and (= 'str (type (cdr x))) (wcmatch (cdr x) "*{*"))
(cons (cons (cdr x) (foo)) (foo))
)
( (cons x (foo)))
)
)
(foo)
)
(defun c:test ( / c e )
(if
(and
(setq e (car (entsel "\nSelect mleader: ")))
(= "MULTILEADER" (cdr (assoc 0 (entget e))))
(setq c 1)
)
(foreach l (LM:mleadervertices e)
(foreach v l
(entmake (list '(0 . "POINT") (cons 10 v) (cons 62 c)))
)
(setq c (1+ (rem c 255)))
)
)
)
Solved! Go to Solution.
Solved by hippe013. Go to Solution.
Solved by hosneyalaa. Go to Solution.
try
(defun LM:mleadervertices ( ent )
(mapcar '(lambda ( x ) (massoc 10 x))
(massoc "LEADER_LINE{"
(cdr
(assoc "LEADER{"
(cdr
(assoc "CONTEXT_DATA{"
(parsedxfdata (entget ent))
)
)
)
)
)
)
)
(defun massoc ( k l )
(mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= k (car x))) l))
)
(defun parsedxfdata ( l / foo )
(defun foo ( / x )
(setq x (car l)
l (cdr l)
)
(cond
( (or (null x) (= "}" (cdr x)))
nil
)
( (and (= 'str (type (cdr x))) (wcmatch (cdr x) "*{*"))
(cons (cons (cdr x) (foo)) (foo))
)
( (cons x (foo)))
)
)
(foo)
)
(defun c:test ( / c e )
(if
(and
(setq e (car (entsel "\nSelect mleader: ")))
(= "MULTILEADER" (cdr (assoc 0 (entget e))))
(setq c 1)
)
(foreach l (LM:mleadervertices e)
(foreach v l
(entmake (list '(0 . "POINT") (cons 10 (list (car v) (cadr v) (atof (vlax-get (vlax-ename->vla-object e) 'textstring)))) (cons 62 c)))
)
(setq c (1+ (rem c 255)))
)
)
)
Works well, thank you. is there anyway to do this for multiple mleaders at a time?
Also some of the multi leaders result in an error. My guess is mleaders that have styles/expressions in the content field.
When trying to modify the test function to grab a selection of objects (ssget) i get lenentityp errors. Any ideas to get the functions to all multiple objects to loop through instead of one object at a time?
Create a selection set using a filter. Then use SSNAME to return the entity from the selectionset. Something like this:
(defun c:test( / ss n c e)
(setq ss (ssget '(( 0 . "MULTILEADER"))))
(if ss
(progn
(setq n 0)
(repeat (sslength ss)
(setq ent (ssname ss n))
(foreach l (LM:mleadervertices ent)
(foreach v l
(entmake (list '(0 . "POINT") (cons 10 (list (car v) (cadr v) (atof (vlax-get (vlax-ename->vla-object e) 'textstring)))) (cons 62 c)))
)
(setq c (1+ (rem c 255)))
)
(setq n (+ n 1))
)
)
)
(princ)
)
I'm getting this
; error: bad argument type: lentityp nil
Is it because the other functions are using entget instead ssget,sslength,ssname etc. Do entget and ssget work together? Or should I convert the other functions to use ssget as well?
No. It is because in the version I posted I renamed the variable from "e" to "ent". Switching it back to "e" should solve the error.
(defun c:test( / ss n c e)
(setq ss (ssget '(( 0 . "MULTILEADER"))))
(if ss
(progn
(setq n 0)
(repeat (sslength ss)
(setq e(ssname ss n))
(foreach l (LM:mleadervertices e)
(foreach v l
(entmake (list '(0 . "POINT") (cons 10 (list (car v) (cadr v) (atof (vlax-get (vlax-ename->vla-object e) 'textstring)))) (cons 62 c)))
)
(setq c (1+ (rem c 255)))
)
(setq n (+ n 1))
)
)
)
(princ)
)
Well. Removed entmake all together and removed the color index vaiable "c".
(defun c:test( / ss n c e)
(setq ss (ssget '(( 0 . "MULTILEADER"))))
(if ss
(progn
(setq ms (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'ModelSpace))
(setq n 0)
(repeat (sslength ss)
(setq e (ssname ss n))
(foreach l (LM:mleadervertices e)
(foreach v l
(setq elev (atof (setq str (vlax-get (vlax-ename->vla-object e) 'TextString))))
(vlax-invoke-method ms 'AddPoint (vlax-3d-point (car v) (cadr v) elev))
)
)
(setq n (+ n 1))
)
)
)
(princ "\nDone.")
(princ)
)
I tested this code to make sure that it works.
Can't find what you're looking for? Ask the community or share your knowledge.