Jump to content

This lisp is giving me a bad argument type error...


Recommended Posts

Posted

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)
)

Posted

Move the DTR definition to the top of the Routine perhaps ??

... so that it's defined before it's needed.

Posted

also looks like you have a plethora of additional parenthesis.

Posted
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.

Posted

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)
)

Posted

Yeah, when I removed the extra parens it worked fine. Thanks for your help.

Posted
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.

Posted

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.

Posted
...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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...