Jump to content
JoeyG_77

Replacing a Dynamic Block with another

Recommended Posts

JoeyG_77

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

Share this post


Link to post
Share on other sites
BIGAL

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.

Share this post


Link to post
Share on other sites
Emmanuel Delay

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

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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