Vincenzo Posted December 24, 2019 Posted December 24, 2019 Hello, I have no great skills with lisp and I ask you for help. I'm searching a lisp routine that select one dynamic blocks placed in a specific rectangular area and put the current value in a variable. I modified a Lee Mac program but it doesn't work. I don't understand where the error is. I hope for your help.Thanks. (defun LM:getdynpropvalue ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value))) (vlax-invoke blk 'getdynamicblockproperties) ) ) (defun c:02test ( / e x ) (setq ppp (getpoint "\n\t***\tPick higher left corner\t*** \n : ")) (setq x (nth 0 ppp)) (setq y (nth 1 ppp)) (setq x1 (+ x 20.72)) (setq y1 (- y 9.37)) (setq x2 (+ x 3.3)) (setq y2 (- y 7.85)) (if (and (setq e (ssget "_W" (list x1 y1) (list x2 y2))) (= "INSERT" (cdr (assoc 0 (entget e)))) ) (print (setq x (LM:getdynpropvalue (vlax-ename->vla-object e) "Fornitore"))) ) (princ) ) Quote
Lee Mac Posted December 24, 2019 Posted December 24, 2019 (edited) The main issue is that ssget returns a selection set, not an entity name and so you'll first need to obtain the entity name at the first index of the selection set using the ssname function before converting the entity name to a vla-object for use with my function. Consider the following code: (defun c:03test ( / s p x ) (if (setq p (getpoint "\nPick top-left corner: ")) (if (setq s (ssget "_W" (mapcar '+ p '(20.72 -9.37)) (mapcar '+ p '( 3.30 -7.85)) '((0 . "INSERT")) ) ) (print (setq x (LM:getdynpropvalue (vlax-ename->vla-object (ssname s 0)) "Fornitore"))) (princ "\nNo blocks found.") ) ) (princ) ) ;; Get Dynamic Block Property Value - Lee Mac ;; Returns the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) (defun LM:getdynpropvalue ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value))) (vlax-invoke blk 'getdynamicblockproperties) ) ) (vl-load-com) (princ) Edited December 24, 2019 by Lee Mac Quote
Vincenzo Posted December 24, 2019 Author Posted December 24, 2019 Thanks for your great help and explanation. In the meantime I had solved it with the following code. (defun LM:getdynpropvalue ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value))) (vlax-invoke blk 'getdynamicblockproperties) ) ) (defun c:02test ( / e x ) (vl-load-com) (setq ppp (getpoint "\n\t***\tPick higher left corner\t*** \n : ")) (setq x (nth 0 ppp)) (setq y (nth 1 ppp)) (setq x1 (+ x 22.32)) (setq y1 (- y 9.6)) (setq x2 (+ x 3.3)) (setq y2 (- y 7.5)) (setq selection (ssget "_W" (list x1 y1) (list x2 y2)) ) (setq Ent(ssname selection 0)) (setq Vl-Obj Ent) (setq valore (cdr (assoc 0 (entget vl-obj)))) (setq xx (LM:getdynpropvalue (vlax-ename->vla-object vl-obj) "Fornitore")) (princ) ) 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.