View Full Version : WHILE Statement...
BoKirra
2009-03-25, 12:11 AM
Hi ALL,
I have a thought while learning WHILE function.
The purpose of using WHILE function is to restore previous layer after drawing some features.
Here is the sample.
(setq oldLAYER (getvar "clayer"))
(command "_.layer" "set" "ref" "")
(while (not press ENTER key)
(command "circle" insert_point 50) ; insert_point is predefined
(command "circle" point01 10) ; point01 is predefined
(command "circle" point02 100) ; point02 is predefined
and so on...
); end of while
(setvar "clayer" oldLAYER)
NOTE:
1) The user presses ENTER key AGAIN to exit WHILE function after drawing some features.
2) The previous layer will then be restored.
Your helps are much appreciated.
T.Willey
2009-03-25, 12:22 AM
It would be better to have the insertion point of the first circle be the check for the while loop. Then if the user doesn't pick a point, the command will finish, and the layer will be restored.
BoKirra
2009-03-25, 12:30 AM
It would be better to have the insertion point of the first circle be the check for the while loop. Then if the user doesn't pick a point, the command will finish, and the layer will be restored.
Thanks.
Yes, it'll be ok.
But how to write this loop function?
T.Willey
2009-03-25, 01:16 AM
(while (setq CenPt (getpoint "\n Select center point of circle: "))
..... do your circle stuff here
)
BoKirra
2009-03-25, 03:12 AM
(while (setq CenPt (getpoint "\n Select center point of circle: "))
..... do your circle stuff here
)
Thanks. It works.
Supposed I want to do dimensioning in the second exercise with an example below.
What is wrong?
(defun c:dims ()
(while (not *Cancel*)
(command "_dimlinear" pause pause pause)
); end of while
(princ)
); end of dims
I got this message on text screen:
Command: dims
_dimlinear (this is 1st dimension)
Specify first extension line origin or <select object>:
Specify second extension line origin:
Specify dimension line location or
[Mtext/Text/Angle/Horizontal/Vertical/Rotated]:
Dimension text = 692
Command: _dimlinear (this is 2nd dimension)
Specify first extension line origin or <select object>:
Specify second extension line origin:
Specify dimension line location or
[Mtext/Text/Angle/Horizontal/Vertical/Rotated]:
Dimension text = 1170
Command: _dimlinear
Specify first extension line origin or <select object>: (I had to press ENTER key TWICES here to stop it.)
Select object to dimension:
Command: (I had to press ESC key here to stop the routine COMPLETLY.)
irneb
2009-03-25, 02:26 PM
Firstly when you hit Enter the first time the DIMLINEAR command changed to select object mode. Then you hit Enter again ... the dimlinear cmd stopped. Then your while checked the value of *Cancel* again (which has not changed at all) so it starts the loop again.
*Cancel* will never change to anything but nil in this code, so the loop will never finish. The Esc key cancels out of any LISP routine, stopping it without doing anything further.
I'd suggest still picking a point, same a T.Willey suggested for the circ funcfion & checking if user supplied point in while. Then replace 1st of the pauses with the varname you setq'd the getpoint to. You may even have to do this for 2 or 3 points using an (and (setq ...) (setq ...) ...) in the while's check then replacing all 3 pauses with their respective points.
BoKirra
2009-03-26, 12:17 AM
Firstly when you hit Enter the first time the DIMLINEAR command changed to select object mode. Then you hit Enter again ... the dimlinear cmd stopped. Then your while checked the value of *Cancel* again (which has not changed at all) so it starts the loop again.
*Cancel* will never change to anything but nil in this code, so the loop will never finish. The Esc key cancels out of any LISP routine, stopping it without doing anything further.
I'd suggest still picking a point, same a T.Willey suggested for the circ funcfion & checking if user supplied point in while. Then replace 1st of the pauses with the varname you setq'd the getpoint to. You may even have to do this for 2 or 3 points using an (and (setq ...) (setq ...) ...) in the while's check then replacing all 3 pauses with their respective points.
Yes, yours works greatly.
Thanks, again, to you & T.Willey.
:Puffy:
irneb
2009-03-26, 06:53 AM
Glad we could help 8) !!
Hopefully someday you might even reciprocate :mrgreen:. BTW, where are you? From you post times it seems you're not that far off my timezone.
Edit: sorry nooooo , forgot to look at the AM/PM ... you are quite far off from me ... nearly the other side of the globe!
BoKirra
2009-03-26, 07:48 AM
Glad we could help 8) !!
Hopefully someday you might even reciprocate :mrgreen:. BTW, where are you? From you post times it seems you're not that far off my timezone.
Edit: sorry nooooo , forgot to look at the AM/PM ... you are quite far off from me ... nearly the other side of the globe!
Thanks!
Thinking the other way, we're in the same side of the earth.
I'm in south & people calls me an aussie. :lol:
T.Willey
2009-03-26, 04:57 PM
Glad we could help 8) !!
x2.
You're welcome.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.