So I know there are tons of answers out there about setting the dynamic visibility of a block in a drawing. However, as far as I can tell, all of them will change every instance of that block. I have a loop that inserts a block numerous times, and I want to be able to set the visibility state of the block that was just added within that loop.
Here is the code that I use to insert the block (which is a dwg). I explode it right after because it inserts the dwg as a block.
(command
"_.-insert" blkcb "_S" scl "_R" "0" "_non" xyzcb ;; Insert crossbar
)
(command "explode" (cdr (assoc -1 (entget (entlast)))))
I have a good feeling I should be using entmake instead of command (which would solve the above explode issue), but I'm still pretty oblivious to making that work for various scenarios.
The visibility states are "1", "left 1", "right 1", "2", "left 2", "right 2", and "3"
Firstly, the
EXPLODE
operation is needed because you are likely inserting a drawing containing a reference of your block, rather than a drawing containing your block definition. To create a drawing containing the block definition, you should useWBLOCK
in the drawing containing the block reference to write the block definition data to its own separate drawing file - inserting such drawing will then yield a reference of the block. This is standard AutoCAD behaviour.Where the visibility state is concerned, you can make use of my Set Dynamic Block Visibility State function - simply supply the function with a vla block reference object, e.g. assuming this line follows the
INSERT
command: