stretch multiple dynamic blocks

stretch multiple dynamic blocks

arq.jolmor
Explorer Explorer
1,859 Views
5 Replies
Message 1 of 6

stretch multiple dynamic blocks

arq.jolmor
Explorer
Explorer

greetings

 

I need stretching several dynamic blocks (with stretch parameters) at the same time; but here is the problem... the stretch parameters should has different values.

 

for example... I got a dynamic block with a simple stretch paramert (a pipe with a variable length)... I put multiple pipes to the same level but each length is different among them and I need to add 20 cm more to each one (at the same time).

 

is this possible do this with dynamic blocks that contains stretch parameter????

 

thanks a lot

0 Likes
Accepted solutions (1)
1,860 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Probably not with built-in functions.

 

But with LISP could be that done quite easily.

I case you're not familiar with LISP yet read HERE a short tutorial on how to use it.

 

(vl-load-com)

(defun c:DBlocksLengthen (/ sel prp opr dst idx obj old)

  (if (and (setq sel (ssget "_:L" '((0 . "INSERT"))))
           (princ (strcat "\nProperties: " (vl-string-right-trim " -" (apply 'strcat (mapcar '(lambda (x) (strcat x " - ")) (mapcar 'car (LM:getdynprops (vlax-ename->vla-object (ssname sel 0)))))))))
           (setq prp (getstring "\nProperty name (numerical): "))
           (not (initget "/ * - +"))
           (setq opr (read (cond ((getkword "\nOperation (+ - * /) <+>: "))
                                ("+"))))
           (setq dst (getdist "\nValue: "))
           )
    (repeat (setq idx (sslength sel))
      (and (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
           (setq old (LM:getdynpropvalue obj prp))
           (numberp old)
           (LM:setdynpropvalue obj prp ((eval opr) old dst))
           )))
  (princ)
  )
   

;; Get Dynamic Block Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of ((<prop> . <value>) ... )

(defun LM:getdynprops ( blk )
    (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

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

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

 

0 Likes
Message 3 of 6

arq.jolmor
Explorer
Explorer

Thanks a lot

the routine works great

ty, ty, ty, ty

0 Likes
Message 4 of 6

jbohP9BSS
Explorer
Explorer

Hi BeeKeeCZ,

 

I know this topic is old, so I apologize if I should just start a new one.

 

But I'm trying to use your code here to edit the properties of a dynamic block. It seems to work until it gets to the 

(LM:setdynpropvalue obj prp ((eval opr) old dst)) line. Here is where it gives me an
; error: too few arguments
 
error. The dynamic property is a Stretch action on a Linear parameter named BayLength, whose "Dist increment" equals 48 "Dist minimum" equals 48, and "Dist maximum" equals 144.
 
 
Command: DBLOCKSLENGTHEN
Select objects: 1 found
Select objects:
Properties: FrameDepth - Origin - BayLength - Origin
Property name (numerical): BayLength
Operation (+ - * /) <+>: +
Value: 48
48.0
BayLength
; error: too few arguments
 
I know the Operation line isn't really applicable but I made sure that my input there equaled a parameter value that matches the "Dist increment".
 
Do you have any ideas? Is there something I'm doing wrong with LM:setdynpropvalue? I've attached a dwg with my block in it.
 
Thanks again and I apologize if this should be a new thread or something.
0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant

Don't really know. I could not replicate the issue. 

You can try this routine without Lees subs.

 

(vl-load-com)

(defun c:DBlocksLengthen (/ sel prp opr dst idx obj old new)

  (if (and (setq sel (ssget "_:L" '((0 . "INSERT"))))
           (princ (strcat "\nProperties: "
			  (vl-string-right-trim " -" (apply 'strcat (mapcar '(lambda (x) (strcat x " - ")) (mapcar 'vla-get-propertyname (vlax-invoke (vlax-ename->vla-object (ssname sel 0)) 'getdynamicblockproperties)))))))
           (setq prp (strcat "AcDbDynBlockProperty" (getstring "\nProperty name (numerical): ")))
           (not (initget "/ * - +"))
           (setq opr (read (cond ((getkword "\nOperation (+ - * /) <+>: ")) ("+"))))
           (setq dst (getdist "\nValue: "))
           )
    (repeat (setq idx (sslength sel))
      (and (setq ent (ssname sel (setq idx (1- idx))))
	   (or (not (setq err (vl-catch-all-error-p (setq old (vl-catch-all-apply 'getpropertyvalue (list ent prp))))))
	       (prompt (strcat "\nError: " err)))
           (or (numberp old)
	       (prompt "\nError: Numberp prove failed."))
	   (setq new ((eval opr) old dst))
	   (setpropertyvalue ent prp new))))
  (princ)
  )
 

 

0 Likes
Message 6 of 6

jbohP9BSS
Explorer
Explorer

Hi BeeKeeCZ,

 

This worked!!! Thank you so much for your help!

0 Likes