Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp Point at Multileader vertex

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
rjames94
551 Views, 11 Replies

Lisp Point at Multileader vertex

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)))
        )
    )
)

 

Tags (1)
Labels (3)
11 REPLIES 11
Message 2 of 12
hosneyalaa
in reply to: rjames94

@rjames94 

 

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)))
        )
    )
)

7.gif

Message 3 of 12
rjames94
in reply to: hosneyalaa

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.

 

rjames94_0-1713272381765.png

 

Message 4 of 12
hippe013
in reply to: rjames94

Run Strip MText Lisp Prior to running code provided by @hosneyalaa 

 

 

Message 5 of 12
rjames94
in reply to: hippe013

Thanks that solved that issue!
Message 6 of 12
rjames94
in reply to: rjames94

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?

Message 7 of 12
hippe013
in reply to: rjames94

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)
  )
Message 8 of 12
rjames94
in reply to: hippe013

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?

Message 9 of 12
hippe013
in reply to: rjames94

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)
  )

 

Message 10 of 12
rjames94
in reply to: hippe013

I got this error. ; error: bad DXF group: (62)
Removing "(cons 62 c)" solved that. But now i'm getting ; error: bad argument type: numberp: nil
Message 11 of 12
hippe013
in reply to: rjames94

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.  

Message 12 of 12
rjames94
in reply to: hippe013

Thank you! Everything working as expected

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report