@Anonymous wrote:
Henrique,
I was able to get your routine to work, great job and thanks for your effort! Unfortunately it looks like this routine places the new block at the insertion of the existing block rather than an actual block replacement. The issue with this method is the attribute values won't carry over to the new block. I have currently made provisions for each of the different types to be placed on a specific layer that can be isolated to aid in changing the visibility state after doing a blockreplace. This will be a workable solution in our update process. If your tired of my little project feel free to move on. If you would like to continue helping me out perhaps a routine that would select all the "block-1" blocks on layer "layer-1" and change the visibility state to "state-1" would do the trick.
In either case, much thanks for your help!
Brad
Brad,
even using blockreplace, will have to replace one block, for one other using the same insertion point.
Try the revised code, with the attached dwg, with the 'GENERAL INSTRUMENT' redefined by me...
(vl-load-com)
(defun c:demo (/ attlst attlst1 attlst2 b blk i lasthnd lastobj name obj ss vis)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(vla-startundomark adoc)
(if (and (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "IIFM,SDFM,CFFM,PLFM") (cons 410 (getvar 'CTAB)))))
(setq blk "GENERAL INSTRUMENT")
)
(repeat (setq i (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i))))
name (vla-get-effectivename obj)
attlst (vlax-invoke obj 'GetAttributes)
attlst1 nil
)
(foreach a attlst
(setq attlst1 (cons (cons (vla-get-tagstring a) (vla-get-textstring a)) attlst1))
)
(cond ((= name "IIFM")
(setq vis "INDEPENDENT INSTRUMENTS")
)
((= name "SDFM")
(setq vis "SHARED DISPLAY/SHARED CONTROL OF DISTRIBUTED CONTROL SYSTEM")
)
((= name "CFFM")
(setq vis "COMPUTER FUNCTION")
)
(T
(setq vis "PROGRAMMABLE LOGIC CONTROL")
)
)
(command "-insert" blk "_S" 1 "_R" 0 "_NONE" (vlax-get obj 'InsertionPoint))
(setq lasthnd (entlast)
lastobj (vlax-ename->vla-object lasthnd)
attlst2 (vlax-invoke lastobj 'GetAttributes)
)
(foreach a attlst2
(if (setq b (assoc (vla-get-tagstring a) attlst1))
(vla-put-textstring a (cdr b))
)
)
(if (and (vlax-property-available-p lastobj 'IsDynamicBlock)
(eq (vla-get-IsDynamicBlock lastobj) :vlax-true)
)
(progn
(foreach p (vlax-safearray->list
(vlax-variant-value (vla-getdynamicblockproperties lastobj))
)
(if (and (eq (vlax-get p 'PropertyName) "Visibility1")
(vl-position vis (vlax-get p 'AllowedValues))
)
(vlax-put-property p "Value" vis)
)
)
;(vla-delete obj)
)
)
)
)
(vla-endundomark adoc)
(princ)
)
As I said in an earlier post, the vla-delete is commented, just for visual debugging, to erase the original 'INSERT', just remove the ";".
Hope this helps,
Henrique