salman Posted May 30, 2010 Posted May 30, 2010 Sometimes I need to repeatedly use same autolisp routine many times. Each time I have to press space bar to reinvoke the same command. Is it possible to tell autocad to continueuly repeat the command unless we press ESC or repeat the autolisp command by a specified number of times.Thanks. Quote
saim Posted August 10, 2017 Posted August 10, 2017 Same doubt. The "while" loop worked. But I'm confused about the syntaxe. I tried (while (T)'infinite loop, exitted by pressing space, enter or esc (commands)) and the CAD didn't buy it. Then I tried changing to (while(= 1 1)'same thing, written differently (commands)) and it worked. But it looks a little dumb. Is there a good-looking way to put this into code? Quote
ronjonp Posted August 10, 2017 Posted August 10, 2017 Same doubt. The "while" loop worked. But I'm confused about the syntaxe.I tried (while (T)'infinite loop, exitted by pressing space, enter or esc (commands)) and the CAD didn't buy it. Then I tried changing to (while(= 1 1)'same thing, written differently (commands)) and it worked. But it looks a little dumb. Is there a good-looking way to put this into code? It all depends on what you are doing in the loop. Here's a simple example that will place points repeatedly until a point is not picked. (while (setq p (getpoint "\nPick a point: ")) (entmakex (list '(0 . "point") '(8 . "point") (cons 10 p))) ) Quote
Lee Mac Posted August 10, 2017 Posted August 10, 2017 Your first example should be: (while t (command ...) ... ) But using an infinite loop should be avoided where possible. Quote
BIGAL Posted August 11, 2017 Posted August 11, 2017 Re a specified number of times You can use repeat as well as a while (repeat 3 ... your code ) or (setq x 1) (while (< x 4) ...... your code (setq x (+ x 1)) ) 1 Quote
saim Posted October 4, 2017 Posted October 4, 2017 It all depends on what you are doing in the loop. Here's a simple example that will place points repeatedly until a point is not picked. (while (setq p (getpoint "\nPick a point: ")) (entmakex (list '(0 . "point") '(8 . "point") (cons 10 p))) ) Really beginner, here, please comment everything. Although I assume the second line has nothing to do with the loop, it seems pretty interesting. I can't make sense of any of it and will search for those commands. But the point inquestion, here, is the first line. How should I read it? Because right now, I'm reading: "while (command)", which doesn't make sense to me. Should I read "While (whathever the command returns)" and understand that when the user does not click it'll return nill and end the loop? Wow, it DOES make sense! Just confirm, please, if that's that! Quote
ronjonp Posted October 4, 2017 Posted October 4, 2017 Really beginner, here, please comment everything.... Should I read "While (whathever the command returns)" and understand that when the user does not click it'll return nill and end the loop? Wow, it DOES make sense! Just confirm, please, if that's that! Exactly Quote
Jef! Posted October 4, 2017 Posted October 4, 2017 Should I read "While (whathever the command returns)" and understand that when the user does not click it'll return nill and end the loop? not exactly, but close. Whathever the evaluation of the first expression returns. (it could be a variable, a subfunction, or a function, but not really a command, since on top of my head a command never returns "nil"). if we look at ronjp's example, the part that make the while go on or stop is the (setq p (getpoint "\nPick a point: ")). LEts look at it on its own. Command: (setq p (getpoint "\nPick a point: ")) Pick a point: (6.95981 2.86731 0.0) Command: !p (6.95981 2.86731 0.0) The point you pick (if you pick a point) is stored in the variable P. As long as you pick a point, P is non nil, and the second part gets evaluated. It (the enmakex) then creates a graphical point, using the coordinates stored in the variable P. If you were to hit return or spacebar instead, Command: (setq p (getpoint "\nPick a point: "))Pick a point: (hit enter or space bar instead of clicking here) nil Command: !p nil P becomes nil, and the while's evaluation stops. Quote
jonathann3891 Posted October 5, 2017 Posted October 5, 2017 You could create a button on a toolbar put “*” at the beginning the macro and that will cause it to loop. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.