Hi folks,
I am trying to select a dynamic block which contains 4 visibility states and then change to a desire state.
I have achieved my goal partially using Lee Macs functions.
http://www.lee-mac.com/dynamicblockfunctions.html
The trouble is selecting the dynamic block (can not use (entsel)). Routine will run in batch via script so I have to have the block selected without user input.
So I am using this (also a Lee Mac routine with a few changes):
(defun c:DYNBLSTATE ()
(vl-load-com)
(setq s (ssget "_X" '((0 . "INSERT") (2 . "`*U*,Status"))));create selection set that contains block "Status"
(repeat (setq i (sslength s));Count how many entities in selection set...
(setq e (ssname s (setq i (1- i))));...and subtract 1 from selection set total number (integer)
(if e (= "Status" (vla-get-effectivename (vlax-ename->vla-object e)));...until it gets to desired block.
)
)
)
Running that gives me:
!e
<Entity name: 7fffdfa0a40>
The selection set contains 9 entities:
Command: (ssname s 0)
<Entity name: 7fffdfa0a40>
Command: (ssname s 1)
<Entity name: 7fffdfa0960>
Command: (ssname s 2)
<Entity name: 7fffdf38520>
Command: (ssname s 3)
<Entity name: 7fffdf38c40>
Command: (ssname s 4)
<Entity name: 7fffdfac4a0>
Command: (ssname s 5)
<Entity name: 7fffdfa1240>
Command: (ssname s 6)
<Entity name: 7fffdf791c0>
Command: (ssname s 7)
<Entity name: 7fffdf79150>
Command: (ssname s 😎
<Entity name: 7fffdfbe380> - Desired one
Picking the desired Block element directly I get:
(car(entsel))
<Entity name: 7fffdfbe380>
So routine instead of selecting:
<Entity name: 7fffdfbe380>
It goes all the way to the end of repeat and selects last instance:
<Entity name: 7fffdfa0a40>
Can anyone help?
Thanks
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
Hi azmand,
Try the following, modifying the visibility state name to suit:
(defun c:dynblstate ( / i o s ) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "`*U*,Status")))) (repeat (setq i (sslength s)) (if (= "status" (strcase (vla-get-effectivename (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))) t)) (LM:SetVisibilityState o "YourVisibilityStateHere") ) ) ) (princ) ) (vl-load-com) (princ)
You're very welcome azmand - I'm glad it helped.
Cheers!