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

detect if there are objects selected

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
BigDumbWeirdo
1959 Views, 4 Replies

detect if there are objects selected

I'm wondering if anyone knows a way to detect of there are objects currently selected using Autolisp, visual lisp or even VBA. I would like to be able to do something using that as a conditional, so that (assuming the hypothetical variable isSelected is an on/off indicator of whether or not something is selected) I can code something like this:

(if (isSelected)
    (...)
)

 any help would be appreciated.

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: BigDumbWeirdo


@BigDumbWeirdo wrote:

I'm wondering if anyone knows a way to detect of there are objects currently selected . I would like to be able to do something using that as a conditional, so that (assuming the hypothetical variable isSelected is an on/off indicator of whether or not something is selected) I can code something like this:

(if (isSelected)
    (...)
)

....


You can use the implied-selection option in the selection-method argument in (ssget):

 

(if (ssget "_I")

  (...)

)

Kent Cooper, AIA
Message 3 of 5
BigDumbWeirdo
in reply to: Kent1Cooper

Sweet. Two weeks of googling with no results and all it takes is one post on the forums...

Message 4 of 5
Kent1Cooper
in reply to: BigDumbWeirdo


@BigDumbWeirdo wrote:

Sweet. Two weeks of googling with no results and all it takes is one post on the forums...


You can use the same approach to go even further than just determining whether there's anything pre-selected.  For instance, you can find out whether there are any Line entities among a pre-selection:

 

(if (ssget "_I" '((0 . "LINE")))

  (...)

); if

 

And you can do things like put them into a variable directly in the process if there are, but ask the User to pick some if there are not:

 

(if (not (setq liness (ssget "_I" '((0 . "LINE")))))

  (progn ; then -- ask User to select

    (prompt "\nTo [do something with] Lines.")

    (setq liness (ssget '((0 . "LINE"))))

  ); progn

); if

(...do something with liness...)

Kent Cooper, AIA
Message 5 of 5
BigDumbWeirdo
in reply to: Kent1Cooper

Good advice, there. I'll probably be using it, soon.

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

Post to forums  

Autodesk Design & Make Report

”Boost