Stuck on an AutoLISP program

Stuck on an AutoLISP program

Anonymous
Not applicable
385 Views
2 Replies
Message 1 of 3

Stuck on an AutoLISP program

Anonymous
Not applicable

Hi everyone,

I am using Autolisp for the first time and am trying to teach myself how to use it. I started of with programming for a simple stud. The code is working when i give chamfer as big as 5mm, but when i give chamfer value as 0.5mm the output is just a rectangle. I am hoping someone could help me with this. Thanks 🙂

 

Here is the code:

 

 

(defun c:stud ()
;define the function
;********************************************************

;Get User Inputs

(setq lb (getdist "\nLength of Stud : "))
;get the length of the beam

(setq dia (getdist "\nDiameter of Stud : "))
;get the Diameter of Stud

(setq a (getdist "\nChamper length : "))
;get the Champer length

(setq b (getangle "\nChamper angle : "))
;get the Champer angle

;End of User Inputs
;*********************************************************
;Get Insertion Point

(setq ip (getpoint "\nInsertion Point : "))
;get the insertion point

;********************************************************
;Start of Polar Calculations

(setq p2 (polar ip 0.0 a))
(setq p3 (polar ip 0.0 (- lb a)))
(setq p4 (polar p3 b (/ a (cos 20))))
(setq p5 (polar p2 (/ pi 2) dia))
(setq p6 (polar p3 (/ pi 2) dia))
(setq p7 (polar p6 (- 0.0 b) (/ a (cos 20))))
(setq p8 (polar p7 pi lb))
(setq p9 (polar p4 pi lb))
;End of Polar Calculations
;**********************************************************

;Start of Command Function

(command "Line" p2 p3 p6 p5 "c"
"Line" p5 p8 ""
"Line" p8 p9 ""
"Line" p9 p2 ""
"Line" p6 p7 ""
"Line" p7 p4 ""
"Line" p4 p3 ""
) ;End Command
;End of Command Function

;*********************************************************
(princ)
;finish cleanly

) ;end of defun

0 Likes
386 Views
2 Replies
Replies (2)
Message 2 of 3

doglips
Advocate
Advocate

I haven't looked closely at your code but the first thing I would do is make sure that your Osnaps are set to 0 before the code runs

Try this:

(setq OrigOsmode (getvar "osmode"))    ;;get original osnap mode

(setvar "osmode" 0)  ;;changes it to 0

 

Now place your code here

 

Then before your closing paren put:

(setvar "osmode" Origosmode)  ;;returns to original osnap mode

 

0 Likes
Message 3 of 3

BeKirra
Advisor
Advisor

Another is localising the variables created by "setq" in your code.

 

(defun c:stud
(/ lb dia a b ip)
...
)

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes