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

Help with while loop

4 REPLIES 4
Reply
Message 1 of 5
sepult
238 Views, 4 Replies

Help with while loop

I'm trying to create a lisp that draws a mline, than explodes it after the user has picked the necessary points.
I know it needs to have a while loop similar to Plines but, I'm not sure where and how it goes. can anyone help?

(defun C:ML ( /LOOP WID)
(if (= (getvar "USERR1") 0)
(progn (C:DW) (C:ML))
(while (not LOOP)
(setq WID (getdist "\nLine Gap: "))
(progn
(setq LOOP 1)
)
(command "MLINE" "J" "Z" "S" WID )
(command "EXPLODE" "L")

)
)
(princ)

tia
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: sepult

There are various ways people will look at the CMDACTIVE System Variable to test whether the Mline
command has not yet been ended, and keep pausing for user input until it is. Here's one:

....
(command "MLINE" "J" "Z" "S" WID)
(while (> (getvar 'cmdactive) 0) (command pause))
(command "EXPLODE" "L" "")
....

You'll see other approaches, such as whether CMDACTIVE is *not equal to* 0 [instead of greater than
0], or Boolean operations to see whether a 1 bit is part of it, or some other things, any of which
do the job.

[And I added the "" in your Explode command to finish the selection.]

--
Kent Cooper


sepult wrote...
I'm trying to create a lisp that draws a mline, than explodes it after the user has picked the
necessary points.
I know it needs to have a while loop similar to Plines but, I'm not sure where and how it goes. can
anyone help?

(defun C:ML ( /LOOP WID)
(if (= (getvar "USERR1") 0)
(progn (C:DW) (C:ML))
(while (not LOOP)
(setq WID (getdist "\nLine Gap: "))
(progn
(setq LOOP 1)
)
(command "MLINE" "J" "Z" "S" WID )
(command "EXPLODE" "L")

)
)
(princ)

tia
Message 3 of 5
sepult
in reply to: sepult

Thank you for the quick response.
That worked great.
That's much less confusing.
Message 4 of 5
Anonymous
in reply to: sepult

Any time.
--
Kent Cooper


sepult wrote...
Thank you for the quick response.
That worked great.
That's much less confusing.
Message 5 of 5
Anonymous
in reply to: sepult

sepult wrote:

> (defun C:ML ( /LOOP WID)
>
A little detail here: this doesn't do what you likely intended.
- if the idea was to create a function of no arguments, with local
variables LOOP and WID.

What this does is create a function with two arguments named /LOOP and
WID, and no local variables.
Add a space after the / character if you are defining local variables.
A slash is not a delimiter in Lisp, it is a legal constituent in symbol
names:
_$ (setq a/b 😎
8
_$ a/b
8



--

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

Post to forums  

Autodesk Design & Make Report

”Boost