Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic block selection

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
azmand01
1287 Views, 3 Replies

Dynamic block selection

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

 

 

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: azmand01

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)

 

Message 3 of 4
azmand01
in reply to: Lee_Mac

You're the man.
Tested with a script and it worked great.
I have seen many posts on the net where people can not select dynamic blocks unless there is a user input such as (entget) and (entsel)..
I hope it helps others.

Thanks very much.
Message 4 of 4
Lee_Mac
in reply to: azmand01

You're very welcome azmand - I'm glad it helped.

 

Cheers!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost