JoeyG_77 Posted November 12, 2019 Share Posted November 12, 2019 Hey everyone .. Anyone know or have a lisp that will replace one dynamic block with another and take its properties if all of the criteria matches in that block. Thanks Joey G Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 12, 2019 Share Posted November 12, 2019 Lee-mac has a good dynamic block lisp to get the original properties like dynamic name and value. Then erase block insert new and use those values in a new block. You could do a match list of dyn names ((dyn1 dynx)(dyn2 dyny)….. if same order of creation even easier. Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted November 14, 2019 Share Posted November 14, 2019 Not sure if it works for every prop that you need, but try this Command RDP ;; http://www.lee-mac.com/dynamicblockfunctions.html ;; 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) ) ) ;; Set Dynamic Block Properties - Lee Mac ;; Modifies values of Dynamic Block properties using a supplied association list. ;; blk - [vla] VLA Dynamic Block Reference object ;; lst - [lst] Association list of ((<Property> . <Value>) ... ) ;; Returns: nil (defun LM:setdynprops ( blk lst / itm ) (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst)) (foreach x (vlax-invoke blk 'getdynamicblockproperties) (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst)) (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;; ;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/ (defun drawInsert (pt Nme) (entmakex (list (cons 0 "INSERT") (cons 2 Nme) (cons 10 pt))) ) ;;;;;;;;;;;;;;;;;;;;;;;;; ;; returns the common props, so we don't set props that don't exist on the destination block (defun common_props (props1 props2 / res) (setq res (list)) (foreach a props1 ;; see if that prop exists in props2 (if (assoc (car a) props2) ;; skip "Origin" (if (/= "Origin" (car a)) (setq res (append res (list a))) ) ) ) res ) ;; RDP for Replace Dynamic Block (defun c:rdp ( / blk props1 props2 cprops bname pt dblok) ;; read source block (setq blk (car (entsel "\nSelect source block: "))) (setq props1 (LM:getdynprops (vlax-ename->vla-object blk))) ;; insert destination block (setq bname (getstring "\nEnter blockname of the destination block: ")) (setq pt (cdr (assoc 10 (entget blk)))) (setq dblk (drawInsert pt bname)) (setq props2 (LM:getdynprops (vlax-ename->vla-object dblk))) ;; set common props (setq cprops (common_props props1 props2)) (LM:setdynprops (vlax-ename->vla-object dblk) cprops) ;; delete source (entdel blk) (princ) ) Quote Link to comment Share on other sites More sharing options...
Patshai Posted May 3, 2023 Share Posted May 3, 2023 On 11/14/2019 at 3:08 PM, Emmanuel Delay said: This replaces the dynamic block but does not match block properties like rotate, etc. Can you please help. ;; http://www.lee-mac.com/dynamicblockfunctions.html ;; 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) ) ) ;; Set Dynamic Block Properties - Lee Mac ;; Modifies values of Dynamic Block properties using a supplied association list. ;; blk - [vla] VLA Dynamic Block Reference object ;; lst - [lst] Association list of ((<Property> . <Value>) ... ) ;; Returns: nil (defun LM:setdynprops ( blk lst / itm ) (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst)) (foreach x (vlax-invoke blk 'getdynamicblockproperties) (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst)) (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;; ;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/ (defun drawInsert (pt Nme) (entmakex (list (cons 0 "INSERT") (cons 2 Nme) (cons 10 pt))) ) ;;;;;;;;;;;;;;;;;;;;;;;;; ;; returns the common props, so we don't set props that don't exist on the destination block (defun common_props (props1 props2 / res) (setq res (list)) (foreach a props1 ;; see if that prop exists in props2 (if (assoc (car a) props2) ;; skip "Origin" (if (/= "Origin" (car a)) (setq res (append res (list a))) ) ) ) res ) ;; RDP for Replace Dynamic Block (defun c:rdp ( / blk props1 props2 cprops bname pt dblok) ;; read source block (setq blk (car (entsel "\nSelect source block: "))) (setq props1 (LM:getdynprops (vlax-ename->vla-object blk))) ;; insert destination block (setq bname (getstring "\nEnter blockname of the destination block: ")) (setq pt (cdr (assoc 10 (entget blk)))) (setq dblk (drawInsert pt bname)) (setq props2 (LM:getdynprops (vlax-ename->vla-object dblk))) ;; set common props (setq cprops (common_props props1 props2)) (LM:setdynprops (vlax-ename->vla-object dblk) cprops) ;; delete source (entdel blk) (princ) ) Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted May 4, 2023 Share Posted May 4, 2023 @Patshai Anything I can help you with? Quote Link to comment Share on other sites More sharing options...
Steven P Posted May 4, 2023 Share Posted May 4, 2023 Ahh, the question is in the quote I think "This replaces the dynamic block but does not match block properties like rotate, etc. Can you please help." Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 4, 2023 Share Posted May 4, 2023 Here's an existing program to match dynamic parameters between two blocks: https://www.theswamp.org/index.php?topic=44444.msg496892#msg496892 Quote Link to comment Share on other sites More sharing options...
Patshai Posted May 5, 2023 Share Posted May 5, 2023 @Emmanuel @ Lee Mac Thank you for extending the help. I am attaching a drawing of the blocks which we use for our daily work. "PRE-D1200" is the block used for preliminary drawings. After finalization of door types, we would like to replace these blocks with DSL-1200. I would like to replace the selected blocks in one go. Please help. Sample Block Replace.dwg 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.