Jump to content

Recommended Posts

Posted

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

ActionParameters.jpg.44c823c15822145bf97d9fb4418fa67e.jpg

 

The scenario on the right is what I'm looking for.

 

Posted

I don't understand what you're trying to achieve

Posted

I want to grab Postion1 for all the blocks selected and then allow the user to relocate all Positions1 in one go.

 

Animated.gif

Posted (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 by BIGAL
Posted

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?

Posted
  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.

 

Animated.gif

Expand  

If those were circles and lines then you could use the stretch command like so:

2025-04-07_12-48-17.gif.55fe45be878afbdba2cbf80387245866.gif

Posted (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 by Emmanuel Delay
Posted

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

 

Posted

Yes, I don't know how to detect changes of dynamic props.

Anyone, feel free to help me/us here.

 

 

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...