error: bad argument type: numberp: nil

error: bad argument type: numberp: nil

Anonymous
Not applicable
3,602 Views
5 Replies
Message 1 of 6

error: bad argument type: numberp: nil

Anonymous
Not applicable

Creating an autolisp program to add a threaded hole to a selected object, the program is as follows:

 

; Meghan Hendricks
; HOLETHREAD.LSP
;
(defun c:HOLETHREAD ()
(setq scmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq sblip (getvar "blipmode"))
(setvar "blipmode" 0)
(setq sosmd (getvar "osmode"))
(setvar "osmode" 0)
(setq 3dosmd (getvar "3dosmode"))
(setvar "3dosmode" 0)
(setq dyucs (getvar "ucsdetect"))
(setvar "ucsdetect" 0)
(setq ccolor (getvar "cecolor"))
(setq e1 (entsel "\nselect the object"))
(setvar "osmode" 1)
(setq pt1 (getpoint "\nEnter location of new coordinate system: "))
(setq pt2 (getpoint "\nEnter location of new x axis: "))
(setq pt3 (getpoint "\nEnter location of new y axis: "))
(command "ucs" 3 pt1 pt2 pt3)
(setvar "osmode" 0)

(setvar "blipmode" 1)
(setq pt4 (getpoint "\nEnter location of center of the hole on the surface: "))
(setvar "blipmode" 0)
(setq D1 (getreal "\nInput Diameter of the hole: "))
(setq L1 (getreal "\nInput depth of the hole (positive z direction): "))
(setq c (getstring "\nColor of hole"))
(command "color" c)
(command "cylinder" pt4 D1 L1)
(setq e2 (entlast))

(if (>= h 0)
(progn ;- z direction
(setq pt5 (list (car pt4) (+ (cadr pt1) (* D1 0.4)) 0))
(setq pt6 (list (car pt4) (- (car pt1) D2) (- (* D1 0.1))))
(setq pt7 (list (car pt4) (+ (cadr pt1) (* D1 0.4)) (- (* D1 0.2))))
(setq pt8 (list (car pt4) (cadr pt4) (- (* D1 0.1))))
(command "3DPOLY" pt5 pt6 pt7 "c")
(setq e3 (entlast))
(command "helix" pt8 (* 0.4 D1)(* 0.4 D1) "H" (* 0.41 R2) (+ (* 0.4 R2) L1))
(setq e4 (entlast))
(command "sweep" e3 "" "a" "n" e4 "")
(setq e5 (entlast))
(command "subtract" e2 "" e5 "")
(setq e6 (entlast))
)
(progn ;+z direction
(setq pt5 (list (car pt4) (+ (cadr pt1) (* D2 0.4)) 0))
(setq pt6 (list (car pt4) (- (car pt1) D2) (* D1 0.1)))
(setq pt7 (list (car pt4) (+ (cadr pt1) (* D1 0.4)) (* D1 0.1)))
(setq pt8 (list (car pt4) (cadr pt4) (* D1 0.1)))
(command "3DPOLY" pt5 pt6 pt7 "c")
(setq e3 (entlast))
(command "helix" pt8 (* 0.4 D1)(* 0.4 D1) "H" (* 0.41 R2) (+ (* 0.4 R2) L1))
(setq e4 (entlast))
(command "sweep" e3 "" "a" "n" e4 "")
(setq e5 (entlast))
(command "subtract" e2 "" e5 "")
(setq e6 (entlast))
))
(command "subtract" e1 "" e6 "")

(command "ucs" "p")
(command "vpoint" (list 1 -1 1))
(command "vscurrent" 2) ;2d wireframe

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

 

the program gets as far as creating the cylinder or diameter of D1 and then i get the error

 

"error: bad argument type: numberp: nil"

0 Likes
Accepted solutions (1)
3,603 Views
5 Replies
Replies (5)
Message 2 of 6

john.uhden
Mentor
Mentor

The problem I see is in...

 

(if (>= h 0)

 

because I don't see where h has been set.  But it really doesn't matter because if h is nil then (>= h 0) just returns nil.

 

So it must be something else unless you were expecting that (>= h 0).

John F. Uhden

0 Likes
Message 3 of 6

Anonymous
Not applicable

I fixed that to read (>= D1 0)

 

And I am still getting 

 

"error: bad argument type: numberp: nil"

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

R2 is not being set, unless it's coming from somewhere else not shown in this code.

Kent Cooper, AIA
0 Likes
Message 5 of 6

Anonymous
Not applicable

Thank you

0 Likes
Message 6 of 6

Anonymous
Not applicable

i'm working on a similar program mine just adds a while loop what did you set D2 to cause you use it but it is not set

0 Likes