AutoCad Lisp Routines

Moderator: Mike Everman

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

AutoCad Lisp Routines

Post by PyroJoe » Thu Nov 01, 2007 6:11 pm

For those Autocad users who live and die by their lisps. I've decided to add a few of my favorites. Some of these are band-aids to have Autocad to function more like Solidworks.

The first I named "V" for view, use a key to toggle between each while running.


(defun c:v ()
(command "-view" "_swiso" pause)
(command "-view" "_seiso" pause)
(command "-view" "_top" pause)
(command "-view" "_bottom" pause)
(command "-view" "_front" pause)
(command "-view" "_back" pause)
(command "-view" "_left" pause)
(command "-view" "_right" pause)
)
Last edited by PyroJoe on Fri Nov 02, 2007 3:03 pm, edited 2 times in total.

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Post by PyroJoe » Thu Nov 01, 2007 6:16 pm

I call this one XF for X flip, it flips the x coordinate system 90 degrees

(defun c:XF ()

(command "_UCS" "_X" "90")

)


Here is the Y flip

(defun c:YF ()

(command "_UCS" "_Y" "90")

)

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Post by PyroJoe » Thu Nov 01, 2007 6:58 pm

For the more advanced users, A routine that draws a cylinder around an existing line of your choice. It prompts for the Diameter. The .DCL file is included.

(defun c:CY ()

(setq subroutine1 0)
(setq rad1 nil)
(setq rtext 0)


(setq dcl_id (load_dialog "CY.dcl"))

(if (not (new_dialog "CY" dcl_id))
(exit)
)

(mode_tile "editbox1" 2)
(mode_tile "editbox1" 3)


(action_tile
"accept"
"(setq rad1(get_tile \"editbox1\"))(done_dialog)(setq subroutine1 1)"
)

; if ;;accept;; is picked sets rad1 = editbox1's STRING.
; then closes dialogue box
;then set subroutine flag


(action_tile
"cancel"
"(done_dialog)"
)



(start_dialog)


(unload_dialog dcl_id)

;subroutine

(if subroutine1
(progn

(setq rtext (strcat rad1))


(princ rtext)

(setq PLS1 (atof rtext))

(setq PLS2 (/ PLS1 2))

(command "UCS" "w")
;(command "SHADEMODE" "G")


(setq LN1 (entsel))

(setq numbers (entget (car LN1)))

(setq p1 (cdr (assoc 10 numbers)))

(setq p2 (cdr (assoc 11 numbers)))

(command "cylinder" p1 PLS2 "c" p2)

(command "UCS" "p")

)))



------------------Next is the .DCL file

CY : dialog
{

label = "SUPER CYLINDER";


: text {label = "CYLINDER BY DIAMETER";}





: edit_box {label = "DIAMETER:";
key = "editbox1";
fixed_width = true;
edit_width = 10;}


: button {key = "accept";
label = "OK";
is_default = true;
fixed_width = true;
alignment = centered;}

: button {key = "cancel";
label = "cancel";
is_default = false;
fixed_width = true;
alignment = centered;}


}

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Post by PyroJoe » Tue Nov 06, 2007 4:58 pm

Here is my .PGP file, notice 3P for ROTATE3D and XR for EXTRUDE. With this PGP file I normally run without any toolbars. Commands reduced to one or two keystrokes. Hope these help.


3A, *3Darray
3F, *3Dface
3P, *3DORBIT
3Z, *3dzoom
3R, *ROTATE3D
3MR, *MIRROR3D
3MI, *MIRROR3D
A, *ALIGN
Aa, *Area
AAA, *Align
Ar, *Array
ASSO, *DIMREASSOCIATE
At, *Attedit
B, *break
BH, *BHATCH
Bt, *Btrim
Bx, *Bextend
bl, *block
C, *Copy
ce, *CE
CC, *COPYBASE
Cl, *ddcolor
ci, *circle
cd, *ddcolor
cg, *CHPROP
cp, *ddinsert
CU, *SUBTRACT
ct, *subtract
D, *Dist
DA, *dimreassociate
Dd, *Divide
Ddd, *Ddatte
Do, *Donut
Dv, *Dview
DL, *DIMLINEAR
Dp, *DP
Dx, *Dtext
E, *Erase
Ee, *Ddedit
Ex, *Extend
G, *GRIPON
GO, *GRIPOFF
X, *xplode
F, *Filter
Fl, *fillet
Ft, *filter
H, *Hide
HH, *bhatch
I, *Ddinsert
LA, *LAYER
LL, *Lengthen
LE, *QLEADER
L, *Line
Li, *List
Lt, *ddltype
M, *Move
MP, *MATCHPROP
Mi, *Mirror
Ml, *Mline
Mm, *Measure
Ms, *Mspace
MT, *MTEXT
N, *RENDER
O, *Offset
P, *3DPan
pc, *PASTECLIP
Pl, *Pline
Pp, *Pedit
PO, *Polygon
Ps, *Pspace
R, *Regen
Rd, *render
rn, *render
Re, *Regen
REC, *RECTANGLE
Rt, *Rotate
;;;;Rr, *Region
Ro, *rotate
S, *Stretch
Sc, *Scale
SZ, *scale
Ss, *Subtract
T, *Trim
Tl, *dTEXT
Te, *ddedit
Wb, *Wblock
Z, *Zoom
Xt, *extend
xr, *EXTRUDE
x, *explode

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Tue Aug 18, 2009 8:31 pm

AutoCAD Release 2010 has a parametrics menu!
Solid Works must be creating a healthy dent in their income. ha
Attachments
ante.JPG

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Tue Oct 13, 2009 7:00 pm

Also found path animations
Attachments
path animations.JPG

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Tue Oct 13, 2009 7:08 pm

a little bit of fun
Attachments
mpg1.mpg
(613.34 KiB) Downloaded 193 times

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Tue Oct 13, 2009 7:09 pm

fly through
Attachments
mpg2.mpg
(1.79 MiB) Downloaded 218 times

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Fri Sep 10, 2010 4:26 pm

A lisp program I use that draws a circle to find arclength.
Here is the AR1.LSP

(defun c:ar1 ()

;;;;;;;;;;;;;;;;;;;;;;;;gets radius rad1 of selected circle

(setq ci1 (entsel))

(setq numbers (entget (car ci1)))

(setq rad1 (cdr (assoc 40 numbers)))


(setq subroutine1 0)
(setq arcl1 nil)


(setq dcl_id (load_dialog "ar1.dcl"))

(if (not (new_dialog "ar1" dcl_id))
(exit)
)


(mode_tile "editbox1" 2)
(mode_tile "editbox1" 3)


(action_tile
"accept"
"(setq arcl1(get_tile \"editbox1\"))


(done_dialog)(setq subroutine1 1))"
)

;;;;;;;;; if ;;accept;; is picked sets arcleng = editbox1's STRING.
;;;;;;;;;; then closes dialogue box
;;;;;;;;;;;then set subroutine flag


(action_tile
"cancel"
"(done_dialog)"
)



(start_dialog)


(unload_dialog dcl_id)

;;;;;;;;;;;;;;;;subroutine

(if subroutine1
(progn

(setq arcle (atof arcl1))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;starts math to find chord
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;pi divided by 180

(setq piebyonet (/ pi 180))


;;;;;;;;;;;;;;;;;;;;;;;;;;; take resultant piebyonet times rad1

(setq pretheta (* piebyonet rad1))

;;;;;;;;;;;;;;;;;;;;;;;;;;; invert
(setq prethet (/ 1 pretheta))


;;;;;;;;;;;;;;;;;;;;;;;;;;; take resultant prethet times arclength equals angle

(setq theta (* arcle prethet))

;;;;;;;;;;;;;;;;;;;;theta found

;;;;;;;;;;;;;;;;;;;now math for chord length

;;;;;;;;;;;;;;;;;;;;;;;;;;;;two times radius
(setq radsquare (* 2 rad1))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;one half theta
(setq halftheta (/ theta 2))

;;;;;;;;;;;;;;convert half theta to radians to use sin function

(setq haftheta1 (/ halftheta 180))
(setq hafthtaradias (* haftheta1 pi))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;sin of half theta

(setq prechord1 (sin hafthtaradias))

;;;;;;;;;;;;;;;;;;;;;;;; 2 radius times sin half theta is chordlength

(setq chord1 (* radsquare prechord1))

;;;;;;;;;;;;;;;;;;;;gets center point for scribed chord circle


(command "circle" pause chord1)


)))

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Fri Sep 10, 2010 4:28 pm

and the required AR1.DCL

ar1 : dialog
{

label = "FAST ARCLENGTH";

: text {label = "AUTO ARCLENGTH";}


: edit_box {label = "ARCLENGTH:";
key = "editbox1";
fixed_width = true;
edit_width = 10;}


: button {key = "accept";
label = "OK";
is_default = true;
fixed_width = true;
alignment = centered;}

: button {key = "cancel";
label = "cancel";
is_default = false;
fixed_width = true;
alignment = centered;}


}

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Fri Sep 10, 2010 4:46 pm

What use is arclength?
If I create a cone section, and draw circles at both ends, then list the circles, it will show the circumference.

Then if I draw arc#1 and arc#2, then all I need is to create a arclength equal to the circumference to create a template.
to use AR1.LSP I input the diameter value then pick point on the arc that touches the cone section. This creates the circle shown in red intersects arc#1 creating the correct arclength.
Attachments
arclength.JPG
Last edited by PyroJoe on Fri Sep 10, 2010 5:06 pm, edited 1 time in total.

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Fri Sep 10, 2010 4:55 pm

And arclength for arc#2:
Attachments
arclength2.JPG

Mike Everman
Posts: 4926
Joined: Fri Oct 31, 2003 7:25 am
Antipspambot question: 0
Location: santa barbara, CA
Contact:

Re: AutoCad Lisp Routines

Post by Mike Everman » Tue Oct 19, 2010 4:13 am

Nice. I used to love me some autolisp programming.
Mike
__________________________
Follow my technical science blog at: http://mikeeverman.com/
Get alerts for the above on twitter at: http://twitter.com/mikeeverman

PyroJoe
Posts: 1743
Joined: Wed Aug 29, 2007 5:44 pm
Antipspambot question: 125
Location: Texas

Re: AutoCad Lisp Routines

Post by PyroJoe » Mon Jun 20, 2011 3:02 pm


tufty
Posts: 845
Joined: Wed Dec 24, 2003 12:12 pm
Antipspambot question: 0
Location: France
Contact:

Re: AutoCad Lisp Routines

Post by tufty » Wed Jun 22, 2011 8:21 pm

Lisp isn't obfuscated any more than any other language. It's just different (and has a lot of brackets). Once you get your head around it, though, it's the embodiment of beauty.

Other languages are becoming more lisp-ish as time goes on (Ruby *is* a lisp with different syntax, to all intents and purposes, and C/C++/ObjC have grown closures).

http://c2.com/cgi/wiki?GreenspunsTenthRuleOfProgramming
Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp.

Post Reply