TunzaGibbo Posted January 25, 2019 Posted January 25, 2019 I have another question regarding this routine. This routine works perfect and ends perfect when I press "ESCAPE" But it won't end when I press "ENTER" Is there some code I need to the 4th last line? (defun c:conlob (/ *error* Pt1 Pt2 obline) (defun *error* (x) (resetoldvar) (princ "\n*Cancel*") ) (savevartoold) (constructionlayer) (setq Pt1 (getpoint "\nPick First Point:") Pt2 (getpoint Pt1 "\nPick Second Point:")) (command "_xline" Pt1 Pt2 "") (setq obline (entlast)) (while 1 (command "_copy" obline "" Pt2 pause (command))) (resetoldvar) (princ) ) Regards Tony Quote
David Bethel Posted January 25, 2019 Posted January 25, 2019 (edited) You may want to look into (exit) or (quit). A lot of folks are totally against it. Also (if (setq pt1 (getpoint "\nPick 1st Point: ")) (progn ..... )) Could be added Edited January 25, 2019 by David Bethel Quote
TunzaGibbo Posted January 26, 2019 Author Posted January 26, 2019 Thanks David I'm not sure what you mean by EXIT & QUIT Quote
David Bethel Posted January 26, 2019 Posted January 26, 2019 (exit) and (quit) are built in AutoLisp functions. http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-677B9EC8-C35D-4736-AE59-1BDB12E540AF Quote
TunzaGibbo Posted January 26, 2019 Author Posted January 26, 2019 I understand those 2 commands, but I don't want to just add either of them in a line because the copy is on going and I might want to do 50 copies of that line and then I want to press "Escape" or "Enter" to exit the program. I think the (exit) and (quit) need to be added into a WHILE command In other words let me keep copying until I want to stop and then let me out of this program by hitting either the "Escape" or "Enter" keys Regards Tony Quote
Lee Mac Posted January 26, 2019 Posted January 26, 2019 You currently have an infinite loop: the expression (while 1 ...) will continue to evaluate indefinitely as 1 will always evaluate to a non-nil value. The only way to exit such a loop is to force a break in evaluation using ESC. If you wish to exit the program in a standard manner (e.g. using ENTER, SPACE, right-click), then you will need to prompt the user for a point to which the object should be copied (using getpoint), and then test for valid input received before proceeding. For example: (while (setq pt1 (getpoint "\nSpecify point <exit>: ")) (command "_.copy" obline "" "_non" Pt2 "_non pt1) ) You may also want to look into using the COPYMODE system variable, as this will avoid the need for a loop entirely. Quote
TunzaGibbo Posted January 30, 2019 Author Posted January 30, 2019 Thanks Lee I have replaced the first one with the second and it exits with "ESCAPE" or "ENTER" I don't know why I was making it so hard but using "xline " then "A" Autocad says "Enter angle of xline (0.00) or [Reference]: I didn't think to just pick 2 points here (defun c:conlob (/ *error* Pt1 Pt2 obline) (defun *error* (x) (resetoldvar) (princ "\n*Cancel*") ) (savevartoold) (constructionlayer) (setq Pt1 (getpoint "\nPick First Point:") Pt2 (getpoint Pt1 "\nPick Second Point:")) (command "_xline" Pt1 Pt2 "") (setq obline (entlast)) (while 1 (command "_copy" obline "" Pt2 pause (command))) (resetoldvar) (princ) ) (defun c:conlobl (/ Pt1 Pt2 obline) (savevartoold) (constructionlayer) (setq Pt1 (getpoint "\nPick First Point:") Pt2 (getpoint Pt1 "\nPick Second Point:")) (command "_xline" "A" Pt1 Pt2) (while (= (getvar "cmdactive") 1) (vl-cmdf "\\")) (resetoldvar) (princ) ) 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.