DavidP Posted April 3 Posted April 3 Is it possible to select dynamic blocks and activate action parameters... similar to Shift+left click on block grips? (defun c:foo () (vl-load-com) (setq ssTestSet (ssadd)) (princ "\nSelect Test block(s): ") (setq ss (ssget '((0 . "INSERT")(2 . "`*U*")))) (if ss (progn (setq ssTestBlocks '()) (setq i 0) (repeat (sslength ss) (setq blkRef (ssname ss i) effname (vla-get-EffectiveName (vlax-ename->vla-object blkRef)) i (+ i 1)) (if (= (strcase effname) "TEST") (progn (ssadd blkRef ssTestSet) ) ) ) (if ssTestSet (progn (sssetfirst nil ssTestSet) ;Add Activate Position1 action parameter Code Here ;Similar to Shift+left click on grips ) (princ "\nNo blocks named 'Test' were found.") ) ) (princ "\nNo blocks found with names starting with '*U*'.") ) (princ) ) foo_ActionParameter.dwgFetching info... The scenario on the right is what I'm looking for. Quote
DavidP Posted Friday at 12:50 PM Author Posted Friday at 12:50 PM I want to grab Postion1 for all the blocks selected and then allow the user to relocate all Positions1 in one go. Quote
BIGAL Posted Friday at 10:27 PM Posted Friday at 10:27 PM (edited) Ok 1st step is get a copy of this program by Lee Mac, https://lee-mac.com/dynamicblockfunctions.html You want to change the values of Position1_X & _Y, this can be done using Lee's code. ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) Also look at LM:getdynpropvalue so get the current value and +- to that value. Have a go if you get stuck we are here. Edited Friday at 10:29 PM by BIGAL Quote
troggarf Posted Sunday at 12:31 AM Posted Sunday at 12:31 AM I selected both dumb blocks and dynamic blocks at all of the clickable points. I still don't understand what you speak of by saying "similar to Shift+left click on block grips?". I was curious that I missed out on something, but didn't see anything... Do you have a loaded tool that lets you Shift + left click on a grip that does something that the rest of us don't have? Quote
ronjonp Posted Monday at 06:48 PM Posted Monday at 06:48 PM On 4/4/2025 at 12:50 PM, DavidP said: I want to grab Postion1 for all the blocks selected and then allow the user to relocate all Positions1 in one go. Expand If those were circles and lines then you could use the stretch command like so: Quote
Emmanuel Delay Posted Tuesday at 11:48 AM Posted Tuesday at 11:48 AM (edited) I got it. This is what you want, I think. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GET ;; 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) ) ) ;; Get Dynamic Block Property Allowed Values - Lee Mac ;; Returns the allowed values for a specific Dynamic Block property. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: [lst] List of allowed values for property, else nil if no restrictions (defun LM:getdynpropallowedvalues ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues))) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SET ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:foo ( / ssTestSet ss i ssTestBlocks blkRef effname src_ props ps pe) ;; you need to declare the local variables like this. (vl-load-com) (setq ssTestSet (ssadd)) (princ "\nSelect Test block(s): ") (setq ss (ssget '((0 . "INSERT")(2 . "`*U*")))) (if ss (progn (setq ssTestBlocks '()) (setq i 0) (repeat (sslength ss) (setq blkRef (ssname ss i) effname (vla-get-EffectiveName (vlax-ename->vla-object blkRef)) i (+ i 1)) (if (= (strcase effname) "TEST") (progn (ssadd blkRef ssTestSet) ) ) ) (if ssTestSet (progn (sssetfirst nil ssTestSet) ;Add Activate Position1 action parameter Code Here ;Similar to Shift+left click on grips ;; USER selects 2 points (princ "\nMove the dynamic points, pick start point and end point: ") (while (setq ps (getpoint "\nStart point (or press Enter): ")) (setq pe (getpoint ps "\nEnd point: ")) (setq i 0) (repeat (sslength ss) (setq src_ (vlax-ename->vla-object (ssname ss i))) (setq props (list (LM:getdynpropvalue src_ "Position1 X" ) (LM:getdynpropvalue src_ "Position1 Y" ) )) (setq pol_x (nth 0 (polar props (angle ps pe) (distance ps pe) ))) (setq pol_y (nth 1 (polar props (angle ps pe) (distance ps pe) ))) (LM:setdynpropvalue src_ "Position1 X" pol_x) (LM:setdynpropvalue src_ "Position1 Y" pol_y) (setq i (+ i 1)) ) ) ) (princ "\nNo blocks named 'Test' were found.") ) ) (princ "\nNo blocks found with names starting with '*U*'.") ) (princ) ) What's a little different from what you expect: You don't actually get to move one of the dynamic positions. Instead you give 2 points. You can pick a point startting from one of the blocks, but you don't have to. I put it in a WHILE loop EDIT: Thinking about it... I can use this code myself. I just need to remove the part where it only works on blockname "TEST" and parameter "Position1" Edited Tuesday at 12:15 PM by Emmanuel Delay Quote
DavidP Posted Tuesday at 12:47 PM Author Posted Tuesday at 12:47 PM Thanks Emmanuel Delay, BIGAL. This works the only drawback is we lose instant redraw of the graphics while move the mouse. Would be nice to preview the result before committing to the second point. I found this response(a bit old now not sure if still true) and maybe I need to look into .NET https://forums.augi.com/showthread.php?160765-Activate-block-grip-with-lisp Quote
DavidP Posted Tuesday at 01:41 PM Author Posted Tuesday at 01:41 PM I'm made a change so we are using the filtered selection set instead of the original selection, and check the length of filtered set is greater than zero. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GET ;; https://www.lee-mac.com/ ;; 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) ) ) ;; Get Dynamic Block Property Allowed Values - Lee Mac ;; Returns the allowed values for a specific Dynamic Block property. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: [lst] List of allowed values for property, else nil if no restrictions (defun LM:getdynpropallowedvalues ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues))) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SET ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:foo ( / ssTestSet ss i ssTestBlocks blkRef effname src_ props ps pe) ;; you need to declare the local variables like this. (vl-load-com) (setq ssTestSet (ssadd)) (princ "\nSelect Test block(s): ") (setq ss (ssget '((0 . "INSERT")(2 . "`*U*")))) (if ss (progn (setq ssTestBlocks '()) (setq i 0) (repeat (sslength ss) (setq blkRef (ssname ss i) effname (vla-get-EffectiveName (vlax-ename->vla-object blkRef)) i (+ i 1)) (if (= (strcase effname) "TEST") (progn (ssadd blkRef ssTestSet) ) ) ) (if (> (sslength ssTestSet) 0) (progn (sssetfirst nil ssTestSet) ;Add Activate Position1 action parameter Code Here ;Similar to Shift+left click on grips ;; USER selects 2 points (princ "\nMove the dynamic points, pick start point and end point: ") (while (setq ps (getpoint "\nStart point (or press Enter): ")) (setq pe (getpoint ps "\nEnd point: ")) (setq i 0) (repeat (sslength ssTestSet) (setq src_ (vlax-ename->vla-object (ssname ssTestSet i))) (setq props (list (LM:getdynpropvalue src_ "Position1 X" ) (LM:getdynpropvalue src_ "Position1 Y" ) )) (setq pol_x (nth 0 (polar props (angle ps pe) (distance ps pe) ))) (setq pol_y (nth 1 (polar props (angle ps pe) (distance ps pe) ))) (LM:setdynpropvalue src_ "Position1 X" pol_x) (LM:setdynpropvalue src_ "Position1 Y" pol_y) (setq i (+ i 1)) ) ) ) (princ "\nNo blocks named 'Test' were found.") ) ) (princ "\nNo blocks found with names starting with '*U*'.") ) (princ) ) Quote
Emmanuel Delay Posted Tuesday at 01:49 PM Posted Tuesday at 01:49 PM Yes, I don't know how to detect changes of dynamic props. Anyone, feel free to help me/us here. Quote
BIGAL Posted Tuesday at 11:36 PM Posted Tuesday at 11:36 PM I can see insert the block multiple times, but how do you determine where the end points will end up ? In your sample you have 3 left 1 right. You could insert the block one at a time and imply the X & Y offset from the insert point. For me a dcl would pop up with input X & Y so say X for each insert remains the same. As I suggested to change the block you can select one or more and change the position_X or Y, another option would be to say match X or match Y for multiple blocks. 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.