- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
Solved! Go to Solution.