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

Stop while with enter

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
msarqui
1282 Views, 7 Replies

Stop while with enter

Hi,

 

In my head this should be simple, but I am not able to solve.

I am trying to do something like in the "COPY" command. It is multiple, but if I hit enter the command stops.

 

In this exemple:

 

(defun c:SWW ()

(while

(princ "\nSelect objects or Exit")

...my routine here...

);while

);defun

 

If I hit enter at the "Select objects or Exit" promp, the command will stops. Is that possible or I am dreaming?

 

Thanks!

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: msarqui

Perhaps...

 

(defun c:SWW ()
(while (and (princ "\nSelect objects or Exit")
            (setq ss (ssget))
            )

...my routine here...

);while
);defun

 

Henrique

EESignature

Message 3 of 8
Moshe-A
in reply to: msarqui

Hi,

 

the (ssget) function will pause (like any standard command select objects) until you finish your selection or exist with escape.

 

(if (setq ss (ssget))

 (progn

  ; your code continues here (if the selection not fails)

 

 )

)

 

so there is no need for (while) function

 

Moshe

 

Message 4 of 8
msarqui
in reply to: hmsilva

Perfect Henrique!

 

That was exctly what I was looking for.

 

Thanks also to Moshe-A for your answer, but I realy needed the WHILE to repeat the command.

 

Thanks to all!

Message 5 of 8
hmsilva
in reply to: msarqui

You're welcome, msarqui
Glad I could help

Henrique

EESignature

Message 6 of 8
scot-65
in reply to: msarqui

Another method:
Select object first, check if OK at the while, my routine here, select another object, end the while.

(setq s (entsel "Select an object: "))
(while s
...my routine here...
(setq s (entsel "Select another object: "))
);while


??

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 7 of 8
Kent1Cooper
in reply to: msarqui


@msarqui wrote:

....

I am trying to do something like in the "COPY" command. It is multiple, but if ... enter at the "Select objects or Exit" promp, the command will stops. Is that possible or I am dreaming?

....


If you want to do something like that and also allow options additional to just selecting something or exiting, one way to go about it is illustrated in two routines of mine at the Cadalyst CAD Tips website, one to put Text labels on things and Break them around the Text, and another to do the same but Mask behind the Text rather than Break the labeled objects.  They both make use of the ERRNO System Variable.  They spell out available options [in this case mostly about the characteristics of the Text labels, but also including a one-at-a-time internal Undo] in an (initget) function, and use (entsel) in a (while) loop for the User to select an object, offering those options with <exit> as the default.  A (cond) function looks at what the User did in response -- selected something, typed an allowable option, or hit Enter/space.  If the User hit Enter/space, (getvar 'errno) returns 52, and the (cond) function sees that and sets a variable that stops the (while) loop to exit the routine.  [The same approach could be used without the additional-options possibility, but that could be considered overkill in that simpler situation, compared to the suggestions already made here.]

Kent Cooper, AIA
Message 8 of 8
msarqui
in reply to: scot-65


@scot-65 wrote:
Another method:
Select object first, check if OK at the while, my routine here, select another object, end the while.

(setq s (entsel "Select an object: "))
(while s
...my routine here...
(setq s (entsel "Select another object: "))
);while


Nice one Scot

I used your solution for another routine.

Thanks!

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

Post to forums  

Autodesk Design & Make Report

”Boost