gsc Posted January 19, 2021 Share Posted January 19, 2021 Hi, I have a lisp function which returns a list of dynamic block properties: (defun getdynprops ( blk / lst ) (vl-load-com) (setq lst (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value))) (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicblockproperties) ) ) ) Since my dynamic block only has a number of "polar stretch" parameter/actions , which exist of a Distance and an Angle property. The function returns a list like: ((<Angle1> . <Value>) (<Distance1> . <Value>) (<Angle2> . <Value>) (<Distance2> . <Value>) (<Angle3> . <Value>) (<Distance3> . <Value>) ... ) But my goal is to pair the Angle and Distance property in the list. e.g. ( ((<Angle1> . <Value>) (<Distance1> . <Value>)) ((<Angle2> . <Value>) (<Distance2> . <Value>)) ((<Angle3> . <Value>) (<Distance3> . <Value>)) ... ) How do I achieve this? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 19, 2021 Share Posted January 19, 2021 Untested. (defun getdynprops (blk / r) (mapcar '(lambda (x / l) (if l (setq r (cons (append l (cons (vla-get-propertyname x) (vlax-get x 'value))) r) l nil) (setq l (cons (vla-get-propertyname x) (vlax-get x 'value))) ) ) (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicblockproperties) ) r ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted January 19, 2021 Share Posted January 19, 2021 Here's another assuming that you have ALL matching Angle/Distance properties. (defun getdynprops (blk) (mapcar '(lambda (x) (cons (vla-get-propertyname x) (vlax-get x 'value))) (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicblockproperties) ) ) (if (setq r (getdynprops (car (entsel)))) (progn (setq r (vl-sort r '(lambda (r j) (< (car r) (car j))))) (mapcar '(lambda (r j) (list r j)) r (member (nth (/ (length r) 2) r) r)) ) ) Quote Link to comment Share on other sites More sharing options...
gsc Posted January 20, 2021 Author Share Posted January 20, 2021 22 hours ago, Tharwat said: Untested. (defun getdynprops (blk / r) (mapcar '(lambda (x / l) (if l (setq r (cons (append l (cons (vla-get-propertyname x) (vlax-get x 'value))) r) l nil) (setq l (cons (vla-get-propertyname x) (vlax-get x 'value))) ) ) (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicblockproperties) ) r ) (vl-load-com) This returns all NIL values Quote Link to comment Share on other sites More sharing options...
gsc Posted January 20, 2021 Author Share Posted January 20, 2021 15 hours ago, ronjonp said: Here's another assuming that you have ALL matching Angle/Distance properties. (defun getdynprops (blk) (mapcar '(lambda (x) (cons (vla-get-propertyname x) (vlax-get x 'value))) (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicblockproperties) ) ) (if (setq r (getdynprops (car (entsel)))) (progn (setq r (vl-sort r '(lambda (r j) (< (car r) (car j))))) (mapcar '(lambda (r j) (list r j)) r (member (nth (/ (length r) 2) r) r)) ) ) For the IF part you could also use a Lee Mac sub function: (defun group-n ( l n / r ) (if l (cons (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r)) (group-n l n) ) ) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted January 20, 2021 Share Posted January 20, 2021 (edited) 5 hours ago, gsc said: For the IF part you could also use a Lee Mac sub function: (defun group-n ( l n / r ) (if l (cons (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r)) (group-n l n) ) ) ) The list still has to be sorted alphabetically and broken in two so not sure how that would work per your original example. Edited January 20, 2021 by ronjonp Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 20, 2021 Share Posted January 20, 2021 The functions posted so far rely on a number of assumptions: All dynamic block properties returned by the ActiveX getdynamicblockproperties method are either Angle or Distance parameters (in reality, there will also be many origin parameters) There are equal numbers of Angle & Distance parameters, perfectly paired As such, if you wanted to be certain that you were pairing a parameter named "Angle1" with a parameter named "Distance1" and so on, you may need to use somewhat uglier code such as the following: (defun getdynprops ( blk / ang dis nme ) (foreach prp (reverse (vlax-invoke blk 'getdynamicblockproperties)) (setq nme (strcase (vla-get-propertyname prp) t)) (cond ( (wcmatch nme "angle#*") (setq ang (cons (cons nme (vlax-get prp 'value)) ang)) ) ( (wcmatch nme "distance#*") (setq dis (cons (cons nme (vlax-get prp 'value)) dis)) ) ) ) (vl-remove-if-not 'cadr (mapcar '(lambda ( a ) (list a (assoc (strcat "distance" (substr (car a) 6)) dis))) ang) ) ) 1 Quote Link to comment Share on other sites More sharing options...
gsc Posted January 21, 2021 Author Share Posted January 21, 2021 9 hours ago, Lee Mac said: The functions posted so far rely on a number of assumptions: All dynamic block properties returned by the ActiveX getdynamicblockproperties method are either Angle or Distance parameters (in reality, there will also be many origin parameters) There are equal numbers of Angle & Distance parameters, perfectly paired As such, if you wanted to be certain that you were pairing a parameter named "Angle1" with a parameter named "Distance1" and so on, you may need to use somewhat uglier code such as the following: (defun getdynprops ( blk / ang dis nme ) (foreach prp (reverse (vlax-invoke blk 'getdynamicblockproperties)) (setq nme (strcase (vla-get-propertyname prp) t)) (cond ( (wcmatch nme "angle#*") (setq ang (cons (cons nme (vlax-get prp 'value)) ang)) ) ( (wcmatch nme "distance#*") (setq dis (cons (cons nme (vlax-get prp 'value)) dis)) ) ) ) (vl-remove-if-not 'cadr (mapcar '(lambda ( a ) (list a (assoc (strcat "distance" (substr (car a) 6)) dis))) ang) ) ) Thanx man this is working, although I had to change the wcmatch search string "angle#*" and "distance#*" to "angle*" and "distance*", otherwise I got al nil values Quote Link to comment Share on other sites More sharing options...
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.