(setq xlist (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," "DaBlock")))))
(defun c:foo ( / blk dbp dif idx new obj prn prp ref rep sel spc tmp )
(setq blk "DaBlock" ;; block name
new "DaBlockNew" ;; new block name
prp "AFF" ;; dynamic block prop name
dif 2759.336209736222 ;; insertion point difference
)
(cond
( (not
(setq sel
(ssget "_X"
(list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk))
(if (= 1 (getvar 'cvport))
(cons 410 (getvar 'ctab))
'(410 . "Model")
)
)
)
)
)
(prompt (strcat "\nNo references of " blk " found in active drawing."))
)
( (not (setq rep (LM:importblock new)))
(prompt (strcat "\n" new " block not found."))
)
( t
(setq spc
(vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
(if (= 1 (getvar 'cvport))
'paperspace
'modelspace
)
)
)
(repeat (setq idx (sslength sel))
(if (and (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
(= (strcase blk) (strcase (vla-get-effectivename obj)))
(= :vlax-true (vla-get-isdynamicblock obj))
(setq dbp (vlax-invoke obj 'getdynamicblockproperties))
(setq dbp (mapcar '(lambda ( x ) (cons (strcase (vla-get-propertyname x)) x)) dbp))
(not (assoc (strcase prp) dbp))
(vlax-write-enabled-p obj)
)
(progn
(setq ref
(vla-insertblock spc
(vlax-3D-point
(polar
(vlax-get obj 'insertionpoint)
(+ (/ pi 2.0) (vla-get-rotation obj))
(- dif)
)
)
rep
(vla-get-xscalefactor obj)
(vla-get-yscalefactor obj)
(vla-get-zscalefactor obj)
(vla-get-rotation obj)
)
)
(foreach prp '(layer color lineweight linetype)
(vlax-put-property ref prp (vlax-get-property obj prp))
)
(foreach prp (vlax-invoke ref 'getdynamicblockproperties)
(cond
( (= "CLG" (setq prn (strcase (vla-get-propertyname prp))))
(if (setq tmp (cdr (assoc "DISTANCE1" dbp)))
(vla-put-value prp
(vlax-make-variant (+ (vlax-get tmp 'value) dif)
(vlax-variant-type (vla-get-value tmp))
)
)
)
)
( (= "VISIBILITY1" prn)
(if (setq tmp (cdr (assoc "VISIBILITY1" dbp)))
(vla-put-value prp (vla-get-value tmp))
)
)
)
)
)
)
)
)
)
(princ)
)
;; Import Block Definition - Lee Mac
(defun LM:importblock ( blk / bse cmd ext pth )
(setq pth (vl-string-translate "/" "\\" (vl-filename-directory blk))
ext (cond ((vl-filename-extension blk)) (".dwg"))
bse (vl-filename-base blk)
)
(if (/= "" pth) (setq pth (strcat pth "\\")))
(cond
( (tblsearch "block" bse) bse)
( (setq blk (findfile (strcat pth bse ext)))
(setq cmd (getvar 'cmdecho))
(setvar 'cmdecho 0)
(command "_.-insert" blk nil)
(setvar 'cmdecho cmd)
(if (tblsearch "block" bse) bse)
)
)
)
(vl-load-com) (princ)
(ssget "_X"
(list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk))
(if (= 1 (getvar 'cvport))
(cons 410 (getvar 'ctab))
'(410 . "Model")
)
)
)
Can be replaced by:(ssget "_A" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk))))
@ Lee: Do you have a particular reason for not using the "_A" option of the ssget function?
One of these will have the answer
Replace Block (http://goo.gl/Urp24G)