
Originally Posted by
kwest
I have 4 Blocks with 20-50 instances of each block in a drawing. All 6 have a dual state visibility setting A) Design Layout B) Technical Layout. I would like for a LISP to globally change the visibility state of all these blocks. It takes me forever to manually change all these blocks back and forth, I've also tried to place both types on different layer and just toggle the layers but it's twice the work.
I'm LISP dumb, so any help would be greatly appreciated.
Blocks Names are:
BOXTAG - CEILING
BOXTAG - FLOOR
BOXTAG - WALL
BOXTAG - WIRELESS
Visibility States are:
Design
Technical
Here is something to try out. Please note this has not been fully tested and contains no error checking. If you have questions, please ask. I have placed comments, you can see them in red.
Code:
(defun c:MKSx-ToggleDesTech
(
/
dyn
idx
lstBNames
lstDyns
ss
)
;;get a selection set of all blocks in drawing
;;we need to filter for effective name of blocks after the selection is made
(setq ss (ssget "X" (list (cons 0 "INSERT")))
;;this is a list of all the block names to filter for
lstBNames (list "BOXTAG - CEILING"
"BOXTAG - FLOOR"
"BOXTAG - WALL"
"BOXTAG - WIRELESS"
)
idx 0
)
;;if a selection set has been made, process it
(if ss
(progn
(while (< idx (sslength ss))
;;convert each entity to an object (in turn)
(setq obj (vlax-EName->vla-Object (ssname ss idx))
idx (1+ idx)
)
;;if the effective name of the block is in the list above...
(if (member (vla-Get-EffectiveName obj) lstBNames)
;;...process it for it dynamic properties
(progn
;;get all the block dynamic properties
(setq lstDyns (vlax-SafeArray->list (variant-Value (vla-GetDynamicBlockProperties obj))))
;;cycle through each property
(foreach dyn lstDyns
;;look for the visibility state
;;NOTE: THIS IS IMPORTANT, the visibility state is the NAME of the visibility parameter
;;it may need to be changed to match what the blocks use
(if (= "Visibility1" (vla-Get-PropertyName dyn))
;;if the block has the Design visibility set...
(if (= "Design" (variant-Value (vlax-Get-Property dyn 'Value)))
;;...set the Technical visibility
(vlax-Put-Property dyn 'Value "Technical")
;;...otherwise, set the Design visibility
(vlax-Put-Property dyn 'Value "Design")
);;end if
);;end if
);;foreach
);;progn
);;end if
);;while
);;progn
);;end if
(princ)
)
I have also highlighted in orange the name of the visibility state. I have placed the default name (Visibility1) in the code. However, if you have given it a different name, then you will need to modify the name in the code.
HTH,