Jebus_kfc Posted July 28, 2010 Posted July 28, 2010 I’m having an issue running a lisp program for automation of structural gusset plates. In my program I’m using a while loop with a yes/no condition. The loop asks you if the gusset is drawn correctly, and if its not it will loop and draw it correctly, but it will ask you if it is drawn correctly again. So I guess my question is once you have looped once and the problem is fixed, is there a way to stop the loop from asking you again. There is more to the program, but this is the loop: (initget "Yes No") (setq yesno (getkword "\nIs gusset drawn correctly? [Yes/No] : ")) (cond ((null yesno) (setq yesno "Yes")) ((= yesno "No") (command ".erase" HLINE line2 line3 gplate "" ".reverse" line1 "")) );cond (This part is in between the while loop, so it prompts again.) Sorry if this is confusing. Quote
Lee Mac Posted July 28, 2010 Posted July 28, 2010 Hi Jebus, Welcome to the forums There are many solutions, but probably the most intuitive to understand may be something like: (setq loop t) (while loop ... (initget "Yes No") (if (/= "No" (getkword "\nIs gusset drawn correctly? [Yes/No] <Yes>: ")) (setq loop nil) (command ".erase" HLINE line2 line3 gplate "" ".reverse" line1 "") ) ) Remember to localise the variable 'loop' . Ask if you need any more help, Lee Quote
Jebus_kfc Posted July 28, 2010 Author Posted July 28, 2010 Thanks... well not sure if that will work... it keeps looping. If you want I can copy the whole file and explain it alittle more. Basically to do what I want with it you will need about a 16"X16" rectangle with about a 6" line at about 45 degrees... if you know what a gusset plate is, it will help understand... (defun dtr ( a / ) (* pi (/ a 180.0)) ) (defun rtd ( a / ) (* ( / 180.0 pi) a) ) (defun c:GUSSET ( / old_os old_layer line1 enttype p1 p2 p3 p4 p5 p6 sp ep dist ang ang2 hline sp2 ep2 line2 line3 gplate yesno) (setvar "cmdecho" 0) ; turns off command echo (setq old_os (getvar "osmode")) ; saves current osnap setting (setvar "osmode" 0) ; turns off object snap (setq old_layer (getvar "clayer")) ; retrieves current layer (while (/= enttype "LINE" ) (setq LINE1 (entsel "\nPick line of HSS: ")) ; gets fist point of HSS (if LINE1 (setq enttype (cdr(assoc 0 (entget (car LINE1)))) ;allows only a line to be selected );setq (alert "\nTry again.") );if );while (setvar "osmode" 32) (setq p1 (getpoint "\nPick Intersection of Column/Base Plate: ") );setq (setvar "osmode" 0) (while (/= yesno "Yes") (setq sp (cdr(assoc 10 (entget (car LINE1)))) ep (cdr(assoc 11 (entget (car LINE1)))) dist (distance sp ep) ang (angle sp ep) ang2 (angle p1 sp) p2 (polar p1 ang2 24) );setq (command ".offset" 6 LINE1 p2 "") (setq HLINE (entlast)) ;hidden line of gusset (command ".CHANGE" "LAST" "" "PROPERTIES" "LAYER" "HIDDEN" "") (setq sp2 (cdr(assoc 10 (entget HLINE)))) (setq ep2 (cdr(assoc 11 (entget HLINE)))) (setq p3 (polar sp2 ang -1.5) p4 (polar ep2 (+ ang (dtr 180 )) -1.5) );setq (setq p5 (list(car p4) (cadr p1)) p6 (list(car p1) (cadr p3)) );setq (command ".layer" "make" "D04" "color" "MAGENTA" "D04" "") (command ".line" sp2 p3 "") (SETQ line2 (ENTLAST)) ;line to side of gusset (command ".line" ep2 p4 "") (SETQ line3 (ENTLAST)) ;line to side of gusset (command ".pline" p3 p6 p1 p5 p4 "" ) (SETQ GPLATE (ENTLAST)) ;plate of gusset (initget "Yes No") ; looping point, loops program (setq yesno (getkword "\nIs gusset drawn correctly? [Yes/No] : ")) (cond ((null yesno) (setq yesno "Yes")) ((= yesno "No") (command ".erase" HLINE line2 line3 gplate "" ".reverse" line1 "")) );cond );while (setvar "osmode" old_os) ; turns on object snap to previous setting (setvar "cmdecho" 1) ; turns command echo back on (setvar "clayer" old_layer) ; sets layer back to befor program );eop ;;; ;;; Quote
Lee Mac Posted July 28, 2010 Posted July 28, 2010 Thanks... well not sure if that will work... it keeps looping. Did you try it? There is no flaw in my logic. Quote
Jebus_kfc Posted July 28, 2010 Author Posted July 28, 2010 I tried it... and i'm not saying your wrong its just when I tried it, I may have not tried it right as in fixed the certain areas... I'll try it again and get back to you. Thanks for your help Quote
Jebus_kfc Posted July 28, 2010 Author Posted July 28, 2010 Ok... well it seems like your "logic" was the same as mine, maybe it is confuseing on exactly what I'm asking... The loop is to promt "Is gusset drawn correctly?" with the option of either yes or no.. if yes then the program is done.. if no then it fixes the problem - then prompts "Is gusset drawn correctly?" again - which is the reason I'm seeking help. Quote
Lee Mac Posted July 28, 2010 Posted July 28, 2010 So you want it to exit either way? Then why use a loop at all, just leave the IF statement at the end to fix it if need be. Quote
Jebus_kfc Posted July 29, 2010 Author Posted July 29, 2010 yeah I thought about that, but I had already wrote the program and was just curious if there was a way to stop the loop... but anyway thanks much for your help Quote
Jebus_kfc Posted July 29, 2010 Author Posted July 29, 2010 Well I got it to work with like you said replaceing the while loop with just the if statement. The reason I didn't want to do that is because I had to basically copy the whole program down under the if statement, but it works!!!! Quote
Lee Mac Posted July 29, 2010 Posted July 29, 2010 Well I got it to work with like you said replaceing the while loop with just the if statement. The reason I didn't want to do that is because I had to basically copy the whole program down under the if statement, but it works!!!! Good to hear. What editor are you using the write/edit the code BTW? Quote
Jebus_kfc Posted July 29, 2010 Author Posted July 29, 2010 I have been and generally only use Visual LISP in AutoCAD... Quote
Lee Mac Posted July 29, 2010 Posted July 29, 2010 Cool - was just checking that you weren't using Notepad, or another non-code editing program as VLIDE in ACAD has a few highlighting options making such changes as you described easy. 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.