PDA

View Full Version : selecting an object



j_r_auden
18th Dec 2004, 12:16 am
I am using
(setq myobject(ssget "_:S"))
to get a single object from the user. However, if the user clicks on empty
space the function simply continues and produces an error later. How can I get my function to wait until the user actually chooses a valid object. Like the "break" function for example. If you don't select an item, you are asked to select an object again.

Thanks for the help

CADTutor
18th Dec 2004, 12:48 am
You need to put your selection function within a while loop that tests to see if an object has been selected. Here's an example:



(setq obj nil)
(while (= obj nil)
(setq obj (entsel "\nSelect object: "))
)



Now it's quite some time since I did any serious LISPing and so there may be a more modern way to go about this but it does work. The user will continue to be prompted until an object is selected.

If you only want a single object, entsel is simpler than ssget because no selection set is required.

David Bethel
18th Dec 2004, 03:07 am
I still prefer (sssget) over (entsel)



(while (or (not ss)
(> (sslength ss) 1))
&#40;princ "\nSelect 1 <filtered> object&#58; "&#41;
&#40;setq ss &#40;ssget &#41;&#41;&#41; ;include filter list
&#40;setq obj &#40;ssname ss 0&#41;&#41;


-David

Fantomas
18th Dec 2004, 10:12 am
One more example with ENTSEL and filter with MEMBER function.


&#40;while
&#40;not
&#40;and
&#40;setq obj&#40;car&#40;entsel "\nSelect text object or Esc to Quit "&#41;&#41;&#41;
&#40;member&#40;cdr&#40;assoc 0&#40;entget obj&#41;&#41;&#41; '&#40;"TEXT" "MTEXT" "ATTRIBUTE"&#41;&#41;
&#41;; end and
&#41;; not
&#41;; end while

CADTutor
18th Dec 2004, 11:55 am
Ah, there you see - I knew there would be a number of different opinions on this and I'm sure that Fuccaro will add another when he sees this.

David, why do you prefer ssget over entget. It seems more complicated?

fuccaro
18th Dec 2004, 01:38 pm
Always you can add extras but a simple SSGET works fine for me...

David Bethel
18th Dec 2004, 02:36 pm
CadTutor,

I've always prefered (ssget) due to fact that you can use Last/Prev/ etc whereas (entsel) is pretty limited. Also (ssget) filtering is a lot is a lot cleaner (IMO ) than after selection entity testing. -David

Fantomas
18th Dec 2004, 03:12 pm
In most cases I too prefer SSGET. However sometimes from aesthetic reasons I use ENTSEL. It is not pleasant to me that at a choice of one object with an option " _:S " the choice by a frame enabled and an inscription ' Select objects:'. 8)

CADTutor
18th Dec 2004, 06:08 pm
Fantomas, you and I are on the same wavelength, Entget is certainly more elegant for selecting a single object. Irrespective of other considerations it is just more beautiful :roll: and anyone who has done any programming/scripting should look for beauty in their code - don't you think?

Certainly it is potentially confusing for the user to be asked to "select objects" when only one object is required.

Fantomas
19th Dec 2004, 06:06 pm
Yes I too such opinion. Unfortunately AutoLISP not always allows to make all beautifully. For example DCL is a parody on HTML, it is necessary to use ObjectDCL and others libruaries for example DosLib. But it limits representation of such programs at forums because demands from the user of loading additional *.arx files. :(

j_r_auden
21st Dec 2004, 05:45 pm
Thanks for the help, don't know why I didn't think of that.