Steven Erickson Posted September 22, 2010 Posted September 22, 2010 I have simple lisp program that creates a star. I borrowed it from Michel Trottier. For some reason when it get to this line ===> (inters pt4 pt1 pt3 pt5), it comes back with a message that says ==> error: bad argument type. Everything seems to be OK in the code as far as I know. Do you see any problems with it? ;; by Michel Trottier ;; (defun c:star (/ osn pt rd pt1 pt2 pt3 pt4 pt5 pt1a pt2a pt3a pt4a pt5a) (setvar "CMDECHO" 0) (setvar "OSMODE" 0) (setq osn (getvar "OSMODE") pt (getpoint "\nGive the center of the star") rd (getdist "\nRadius? : ") pt1 (polar pt (dtr 90) rd) pt2 (polar pt (dtr 162) rd) pt3 (polar pt (dtr 234) rd) pt4 (polar pt (dtr 306) rd) pt5 (polar pt (dtr 18) rd) pt1a (inters pt1 pt3 pt2 pt5) pt2a (inters pt2 pt4 pt1 pt3)) pt3a (inters pt3 pt5 pt2 pt4)) pt4a (inters pt4 pt1 pt3 pt5)) pt5a (inters pt4 pt1 pt2 pt5)) ) (defun dtr (x) (/ (* x pi) 180.0) ) (command "_PLINE" pt1 pt1a pt2 pt2a pt3 pt3a pt4 pt4a pt5 pt5a "C") (setvar "OSMODE" osn) (princ) ) Quote
Kerry Brown Posted September 22, 2010 Posted September 22, 2010 Move the DTR definition to the top of the Routine perhaps ?? ... so that it's defined before it's needed. Quote
Kerry Brown Posted September 22, 2010 Posted September 22, 2010 also looks like you have a plethora of additional parenthesis. Quote
Steven Erickson Posted September 22, 2010 Author Posted September 22, 2010 also looks like you have a plethora of additional parenthesis. I see what you mean by all the extra parenthesis. I'll fix that and and move the function (dtr). Thanks much. Quote
Small Fish Posted September 22, 2010 Posted September 22, 2010 Try this: ;; by Michel Trottier ;; (defun c:star (/ osn pt rd pt1 pt2 pt3 pt4 pt5 pt1a pt2a pt3a pt4a pt5a) (setvar "CMDECHO" 0) (setvar "OSMODE" 0) (setq osn (getvar "OSMODE") pt (getpoint "\nGive the center of the star") rd (getdist "\nRadius? : ") pt1 (polar pt (dtr 90) rd) pt2 (polar pt (dtr 162) rd) pt3 (polar pt (dtr 234) rd) pt4 (polar pt (dtr 306) rd) pt5 (polar pt (dtr 18) rd) pt1a (inters pt1 pt3 pt2 pt5) pt2a (inters pt2 pt4 pt1 pt3) pt3a (inters pt3 pt5 pt2 pt4) pt4a (inters pt4 pt1 pt3 pt5) pt5a (inters pt4 pt1 pt2 pt5) ) (command "_PLINE" pt1 pt1a pt2 pt2a pt3 pt3a pt4 pt4a pt5 pt5a "C") (setvar "OSMODE" osn) (princ) ) (defun dtr (x) (/ (* x pi) 180.0) ) Quote
Steven Erickson Posted September 22, 2010 Author Posted September 22, 2010 Yeah, when I removed the extra parens it worked fine. Thanks for your help. Quote
Kerry Brown Posted September 22, 2010 Posted September 22, 2010 I see what you mean by all the extra parenthesis. I'll fix that and and move the function (dtr). Thanks much. Decide if the DTR is really meant to be local to the routine ; if so add dtr to the local variable list otherwise the definition becomes global and you're wasting the processing time required to redefine it at each invocation of the routine. Quote
Kerry Brown Posted September 22, 2010 Posted September 22, 2010 I also just noticed that you are setting "OSMODE" to 0 before you are saving the variable value to osn. You may have meant to save the value before setting it ; allowing the final (setvar "OSMODE" osn) to restore the presaved value. Quote
Steven Erickson Posted September 22, 2010 Author Posted September 22, 2010 ...if so add dtr to the local variable list otherwise the definition becomes global and you're wasting the processing time... I see what you mean. I'll change that. I also just noticed that you are setting "OSMODE" to 0 before you are saving the variable value to osn. I get it. So, the (OSMODE) will be 0 instead of the original (OSMODE) value. Thanks, very much for your time. 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.