Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

error: bad argument type: symbolp nil

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
Anonymous
4799 Views, 17 Replies

error: bad argument type: symbolp nil

Hi I am typing up an autolisp code that will create the shape of a 3d bolt, my code is as follows:

 

; Meghan Hendricks
; BOLT3D.LSP
;
(defun c:bolt3d ()
(setq scmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq sblip (getvar "blipmode"))
(setvar "blipmode" 1)
(setq sosmd (getvar "osmode"))
(setvar "osmode" 0)
(setq 3dosmd (getvar "3dosmode"))
(setvar "3dosmode" 0)
(setq dyucs (getvar "ucsdetect"))
(setvar "ucsdetect" 0)

(setq A "y")
(While (= A "y")
(setq D1 (getreal "\nInput Diameter of bolt head: "))
(setq L1 (getreal "\nInput Height of bolt head: "))
(setq L2 (getreal "\nInput Overall length of the shank: "))
(setq L3 (getreal "\nInput Length of the threaded portion of the shank: "))
(setq D2 (getreal "\nInput Diameter of the shank: "))
(setq pt1 (getpoint "\nEnter location of center of bolt head: "))

(setq pt2 (list (car pt1) (cadr pt1) L1))
(setq R1 (/ (/ D1 2) (cos (/ pi 6))))
;(setq R2 (/ D2 2))
(setq pt3 (list (+ (car pt1) R1) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt1) (- (- L2 L3))))
(command "cylinder" pt2 pt3 (- L1))

(setq x (- R1 (/ (* D1 0.95) 2)))
(setq y (/ (* (sin (/ pi 6)) x) (cos (/ pi 6))))
(command "chamfer" pt3 "" x y pt3 "")
(setq e1 (entlast))
(command "POLYGON" 6 pt1 "I" R1)
(command "extrude" "l" "" L1)
(command "intersect" e1 "l" "")
(setq e2 (entlast))

if (> L2 L3) (progn
(command "cylinder" pt1 D2 (- (- L2 L3));
(Command "union" e2 "l" "")
))
(set e3 (entlast))
(command "cylinder" pt4 (* D2 0.8) (- L3));
(command "union" e3 "l" "")
(setq e4 (entlast))
(setq pt5 (list (car (+ pt1 (/ D2 2))) (cadr pt2) - L2));
(setq pt6 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.1) - L2)));
(setq pt7 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.2) - L2)));
(command "3dpoly" pt5 pt6 pt7 pt5)
(command "revolve" "l" "" pt1 pt2 "")
(setq e5 (entlast))

(setq n (- fix(/ L3 (* 0.2 D2)) 1))
(while (<= i n)
(command "copy" e5 "" (list 0 0 0) (list 0 0 (* i 0.2 D2)))
(command "union" "l" e4 "")
(setq e4 (entlast))
(setq i (+ i 1))
)

(command "union" e4 e5 "")

(Setq A (getstring "/nDo you want to create another bolt (y or n)")); get string does not expect a # value
)

(command "ucs" "w")
(command "vpoint" (list 1 -1 1))
(command "hide")

(setvar "blipmode" sblip)
(setvar "cmdecho" scmde)
(setvar "osmode" snp)
(setvar "3dosmode" 3dosmd)
(setvar "ucsdetect" dyucs)
)

 

I run this and the program gets part way through (around where the distance L2 - L3 is used) and then I get the error "error: bad argument type: symbolp nil"

 

any suggestions?

17 REPLIES 17
Message 2 of 18
Ranjit_Singh2
in reply to: Anonymous

This is where it fails

(set e3 (entlast))

maybe it should be setq

 

Message 3 of 18
Shneuph
in reply to: Anonymous

I believer you're getting the error from this line.  Take another look:

if (> L2 L3) (progn
(command "cylinder" pt1 D2 (- (- L2 L3));
(Command "union" e2 "l" "")
))
(set e3 (entlast))
(command "cylinder" pt4 (* D2 0.8) (- L3));
(command "union" e3 "l" "")

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 18
Anonymous
in reply to: Ranjit_Singh2

Thank you!

 

I fixed that but now I am getting the error "error: bad argument type: numberp: (23.8036 5.1828 0.0)"

 

Any suggestions

Message 5 of 18
Ranjit_Singh2
in reply to: Anonymous

That is here

(setq pt5 (list (car (+ pt1 (/ D2 2))) (cadr pt2) - L2));
(setq pt6 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.1) - L2)));
(setq pt7 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.2) - L2)));

Pt1 is a list and you are trying to use it as a number. Try retrieving the correct element from the list as (car pt1) or (cadr pt1), you know better which number you need; and then call the "+" operator

 

Message 6 of 18
ВeekeeCZ
in reply to: Anonymous


@Anonymous wrote:

Hi I am typing up an autolisp code that will create the shape of a 3d bolt, my code is as follows:

 

; Meghan Hendricks
; BOLT3D.LSP
;
(defun c:bolt3d ()
(setq scmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq sblip (getvar "blipmode"))
(setvar "blipmode" 1)
(setq sosmd (getvar "osmode"))
(setvar "osmode" 0)
(setq 3dosmd (getvar "3dosmode"))
(setvar "3dosmode" 0)
(setq dyucs (getvar "ucsdetect"))
(setvar "ucsdetect" 0)

(setq A "y")
(While (= A "y")
(setq D1 (getreal "\nInput Diameter of bolt head: "))
(setq L1 (getreal "\nInput Height of bolt head: "))
(setq L2 (getreal "\nInput Overall length of the shank: "))
(setq L3 (getreal "\nInput Length of the threaded portion of the shank: "))
(setq D2 (getreal "\nInput Diameter of the shank: "))
(setq pt1 (getpoint "\nEnter location of center of bolt head: "))

(setq pt2 (list (car pt1) (cadr pt1) L1))
(setq R1 (/ (/ D1 2) (cos (/ pi 6))))
;(setq R2 (/ D2 2))
(setq pt3 (list (+ (car pt1) R1) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt1) (- (- L2 L3))))
(command "cylinder" pt2 pt3 (- L1))

(setq x (- R1 (/ (* D1 0.95) 2)))
(setq y (/ (* (sin (/ pi 6)) x) (cos (/ pi 6))))
(command "chamfer" pt3 "" x y pt3 "")
(setq e1 (entlast))
(command "POLYGON" 6 pt1 "I" R1)
(command "extrude" "l" "" L1)
(command "intersect" e1 "l" "")
(setq e2 (entlast))

if (> L2 L3) (progn ; no parenthesis
(command "cylinder" pt1 D2 (- (- L2 L3));
(Command "union" e2 "l" "")
))
(set e3 (entlast))
(command "cylinder" pt4 (* D2 0.8) (- L3));
(command "union" e3 "l" "")
(setq e4 (entlast))
(setq pt5 (list (car (+ pt1 (/ D2 2))) (cadr pt2) - L2));
(setq pt6 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.1) - L2)));
(setq pt7 (list (car (+ pt1 (/ D2 2))) (cadr pt1) (+ (* D2 0.2) - L2)));
(command "3dpoly" pt5 pt6 pt7 pt5) ;last ""??
(command "revolve" "l" "" pt1 pt2 "")
(setq e5 (entlast))

(setq n (- fix(/ L3 (* 0.2 D2)) 1))

; where is i??
(while (<= i n)
(command "copy" e5 "" (list 0 0 0) (list 0 0 (* i 0.2 D2)))
(command "union" "l" e4 "")
(setq e4 (entlast))
(setq i (+ i 1))
)

(command "union" e4 e5 "")

(Setq A (getstring "/nDo you want to create another bolt (y or n)")); get string does not expect a # value
)

(command "ucs" "w")
(command "vpoint" (list 1 -1 1))
(command "hide")

(setvar "blipmode" sblip)
(setvar "cmdecho" scmde)
(setvar "osmode" snp)
(setvar "3dosmode" 3dosmd)
(setvar "ucsdetect" dyucs)
)

 

I run this and the program gets part way through (around where the distance L2 - L3 is used) and then I get the error "error: bad argument type: symbolp nil"

 

any suggestions?


 

Message 7 of 18
Shneuph
in reply to: Anonymous

Yah, I noticed that too.. Are you using the debugger?  Try setting a break point in the Vlide editor and stepping through the code to find where the error is happening.

 

vlidebreakpoint.jpg

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 8 of 18
Anonymous
in reply to: Ranjit_Singh2

Thank you that helped a lot, I forgot that the car is only for the use of points. 

 

DO you happen to know what this error means "error: bad argument type: numberp: #<SUBR @000001dcc6aefb88 ->" 

 

Maybe not specific to my code but what I should be looking for

Message 9 of 18
Shneuph
in reply to: Anonymous

It is expecting a number but you're giving it a sub..  like:

(+ 20 princ)

 

Look for a > with improper parenthesis.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 10 of 18
john.uhden
in reply to: Anonymous

@Anonymous wrote:

 

"DO you happen to know what this error means "error: bad argument type: numberp: #<SUBR @000001dcc6aefb88 ->" "

 

That is most likely caused by applying an arithmetric function to another function, such as:

 

(setq b (+ setq a))

John F. Uhden

Message 11 of 18
ВeekeeCZ
in reply to: Anonymous


@Anonymous wrote:

Thank you that helped a lot, I forgot that the car is only for the use of points. 

 

@Anonymous you happen to know what this error means "error: bad argument type: numberp: #<SUBR @000001dcc6aefb88 ->" 

 

Maybe not specific to my code but what I should be looking for


Failed the NumberProof test. See HERE

Message 12 of 18
Anonymous
in reply to: Shneuph

I tried adjusting the parenthesis around for the if statements and the while loop and I still keep getting the same errors

Message 13 of 18
Ranjit_Singh2
in reply to: Anonymous


@Anonymous wrote:

I tried adjusting the parenthesis around for the if statements and the while loop and I still keep getting the same errors


post your revised code

Message 14 of 18
Anonymous
in reply to: Ranjit_Singh2

(defun c:bolt3d ()
(setq scmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq sblip (getvar "blipmode"))
(setvar "blipmode" 1)
(setq sosmd (getvar "osmode"))
(setvar "osmode" 0)
(setq 3dosmd (getvar "3dosmode"))
(setvar "3dosmode" 0)
(setq dyucs (getvar "ucsdetect"))
(setvar "ucsdetect" 0)

(setq A "y")
(While (= A "y")
(setq D1 (getreal "\nInput Diameter of bolt head: "))
(setq L1 (getreal "\nInput Height of bolt head: "))
(setq L2 (getreal "\nInput Overall length of the shank: "))
(setq L3 (getreal "\nInput Length of the threaded portion of the shank: "))
(setq D2 (getreal "\nInput Diameter of the shank: "))
(setq pt1 (getpoint "\nEnter location of center of bolt head: "))

(setq pt2 (list (car pt1) (cadr pt1) L1))
(setq R1 (/ (/ D1 2) (cos (/ pi 6))))
;(setq R2 (/ D2 2))
(setq pt3 (list (+ (car pt1) R1) (cadr pt1)))
(setq pt4 (list (car pt1) (cadr pt1) (- (- L2 L3))))
(command "cylinder" pt2 pt3 (- L1))

(setq x (- R1 (/ (* D1 0.95) 2)))
(setq y (/ (* (sin (/ pi 6)) x) (cos (/ pi 6))))
(command "chamfer" pt3 "" x y pt3 "")
(setq e1 (entlast))
(command "POLYGON" 6 pt1 "I" R1)
(command "extrude" "l" "" L1)
(command "intersect" e1 "l" "")
(setq e2 (entlast))

if (> L2 L3) (progn
(command "cylinder" pt1 D2 (- (- L2 L3));
(Command "union" e2 "l" "")
))
(setq e3 (entlast))
(command "cylinder" pt4 (* D2 0.8) (- L3));
(command "union" e3 "l" "")
(setq e4 (entlast))
(setq pt5 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - L2));
(setq pt6 (list (+ (car pt1) (/ D2 2)) (cadr pt1) (+ - L2 (* D2 0.1))));
(setq pt7 (list (+ (car pt1) (/ D2 2)) (cadr pt1) (+ - L2(* D2 0.2))));
(command "3dpoly" pt5 pt6 pt7 pt5)
(command "revolve" "l" "" pt1 pt2 "")
(setq e5 (entlast))

(setq n (- fix (/ L3 (* 0.2 D2)) 1))
(while (<= i n)
(command "copy" e5 "" (list 0 0 0) (list 0 0 (* i 0.2 D2)))
(command "union" "l" e4 "")
(setq e4 (entlast))
(setq i (+ i 1))
)

(command "union" e4 e5 "")

(Setq A (getstring "/nDo you want to create another bolt (y or n)")); get string does not expect a # value
)

(command "ucs" "w")
(command "vpoint" (list 1 -1 1))
(command "hide")

(setvar "blipmode" sblip)
(setvar "cmdecho" scmde)
(setvar "osmode" snp)
(setvar "3dosmode" 3dosmd)
(setvar "ucsdetect" dyucs)
)

Message 15 of 18
Ranjit_Singh2
in reply to: Anonymous

What is this

(+ - L2 (* D2 0.1))))

if you want the negative of L2 then it should be (- L2). "+" operator needs a number and you are passing it a SUBR; operator "-"

 

Message 16 of 18
Anonymous
in reply to: Ranjit_Singh2

Thank you that helped!

I changed my code to now what is shown in bold:

 

(setq pt5 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - L2));
(setq pt6 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - (- L2 (* D2 0.1))));
(setq pt7 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - (- L2 (* D2 0.2))));
(command "3dpoly" pt5 pt6 pt7 pt5)
(command "revolve" "l" "" pt1 pt2 "")
(setq e5 (entlast))

(setq n (- (fix (/ L3 (* 0.2 D2)) 1)))

 

 

now I am getting "error: too many arguments"

Message 17 of 18
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... 

(setq pt5 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - L2));
(setq pt6 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - (- L2 (* D2 0.1))));
....

(setq n (- (fix (/ L3 (* 0.2 D2)) 1)))

 

....

Breaking down to see the component parts:

 

(setq pt5

  (list

    (+ (car pt1) (/ D2 2)) ; the X coordinate [look OK]

    (cadr pt1) ; the Y coordinate [looks OK]

    - L2 ; the Z coordinate -- not right -- needs parentheses around it (- L2)

  ); list

); setq

(setq pt6

  (list

    (+ (car pt1) (/ D2 2)) ; the X coordinate [look OK]

    (cadr pt1) ; the Y coordinate [looks OK]

    - (- L2 (* D2 0.1)) ; the Z coordinate -- not right -- try removing the unaffiliated - sign

  ); list

); setq

 

and similarly for pt7.

 

(setq n

  (-

   (fix (/ L3 (* 0.2 D2)) ; the right parenthesis after 1 below should be at the end of this line instead

   1)

  ); -

); setq

 

[There's a (1-) function that you can use to reduce something by 1, instead of (- whatever 1).]

Kent Cooper, AIA
Message 18 of 18
john.uhden
in reply to: Anonymous

Well, I don't like the looks of this too much...

 

(setq pt5 (list (+ (car pt1) (/ D2 2)) (cadr pt1) - L2))

which returns a list of 4 items, the 3rd of which is '- (the function for subtraction), as in...

 

Command: (nth 2 pt5)
#<SUBR @052fd598 ->

and

Command: (eval -)
#<SUBR @052fd598 ->

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report