bigd632 Posted February 13, 2015 Posted February 13, 2015 I started dabbling with AutoLISP for the first time today at work, so please bear with me since I'm sure my code is ugly My first program involved selecting a series of points and the program would draw perimeter rectangles around the intersecting areas. That portion of the code worked great (so no need to post it). I'm now trying to add another feature to the code, where it asks if there is a mullion or transom, and if there is, you choose two points on the mullion/transom and the program draws an additional rectangle inside the previously-drawn perimeter rectangles. The problem I'm running into is once you enter "m" or "t", the program skips the first getpoint question so I can't get the variables pt9 or pt11. It instead only asks the second getpoint question and proceeds to crash when it tries to find the intersection points, since it is missing variables. Any suggestions for fixing this? (defun c:test (/ oldosmode pt5 pt6 pt7 pt8 pt9 pt10 pt11 pt12 mutr TLpt TRpt MTpt MBpt) (setq pt5 (getpoint "Choose Head Leftmost Stud: ")) (setq pt6 (getpoint "Choose Head Rightmost Stud: ")) (setq pt7 (getpoint "Choose Sill Leftmost Stud: ")) (setq pt8 (getpoint "Choose Sill Rightmost Stud: ")) (setq mutr (getstring "Mullion(m)/Transom(t)/None(n)")) (cond ((= mutr "t") ( (setq pt9 (getpoint "Select Leftmost Stud on Transom: ")) (setq pt10 (getpoint "Select Rightmost Stud on Transom: ")) (setq TLpt (inters pt1 pt2 pt9 pt10 [onseg])) (setq TRpt (inters pt3 pt4 pt9 pt10 [onseg])) (setq oldosmode (getvar "osmode")) (setvar "osmode" 0) (command "_rectangle" "_from" TLpt "@5,-5" "_from" TRpt "@-5,5" "") (setvar "osmode" oldosmode) )) ((= mt "m") ( (setq pt11 (getpoint "Select Upper Stud on Mullion: ")) (setq pt12 (getpoint "Select Lower Stud on Mullion: ")) (setq MTpt (inters pt5 pt6 pt11 pt12 [onseg])) (setq MBpt (inters pt7 pt8 pt11 pt12 [onseg])) (setq oldosmode (getvar "osmode")) (setvar "osmode" 0) (command "_rectangle" "_from" MTpt "@5,-5" "_from" MBpt "@-5,5" "") (setvar "osmode" oldosmode) )) ) (princ) ; Exit Cleanly ) Quote
BIGAL Posted February 13, 2015 Posted February 13, 2015 Try this only removed two brackets per cond not sure it works ran ok not quite sure what its doing without a image or dwg. (cond ((= mutr "t") (setq pt9 (getpoint "Select Leftmost Stud on Transom: ")) (setq pt10 (getpoint "Select Rightmost Stud on Transom: ")) (setq TLpt (inters pt1 pt2 pt9 pt10 [onseg])) (setq TRpt (inters pt3 pt4 pt9 pt10 [onseg])) (setq oldosmode (getvar "osmode")) (setvar "osmode" 0) (command "_rectangle" "_from" TLpt "@5,-5" "_from" TRpt "@-5,5" "") (setvar "osmode" oldosmode) ) ((= mt "m") (setq pt11 (getpoint "Select Upper Stud on Mullion: ")) (setq pt12 (getpoint "Select Lower Stud on Mullion: ")) (setq MTpt (inters pt5 pt6 pt11 pt12 [onseg])) (setq MBpt (inters pt7 pt8 pt11 pt12 [onseg])) (setq oldosmode (getvar "osmode")) (setvar "osmode" 0) (command "_rectangle" "_from" MTpt "@5,-5" "_from" MBpt "@-5,5" "") (setvar "osmode" oldosmode) ) ) Quote
rkmcswain Posted February 13, 2015 Posted February 13, 2015 I didn't look at every single line, but initially I see: (= mt "m") should probably be (= mutr "m") You should accommodate for user entry of UPPER or lower case Your (cond) statements have too many parenthesis (the one after the (=) statement, and it's corresponding closing one should be deleted) Quote
bigd632 Posted February 13, 2015 Author Posted February 13, 2015 Thanks guys, I pieced the suggestions together and I think I've got it complete now. Quote
BIGAL Posted February 14, 2015 Posted February 14, 2015 Have a look at initget you can force an answer to only what you want. (setq mutr (getstring "Mullion(m)/Transom(t)/None(n)")) I would set up a check and use a while so must answer correct press for none or n 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.