Mastering AutoLISP in 80 Minutes Instructor: Lynn Allen Course Summary: AutoLISP has been around for a long time and has
Views 80 Downloads 0 File size 654KB
Mastering AutoLISP in 80 Minutes Instructor: Lynn Allen Course Summary: AutoLISP has been around for a long time and has always separated the AutoCAD green thumbs from the gurus gurus. This course begins by debunking some popular rumors and explores the amount of AutoLISP code used in CAD-dependent industries today. AutoLISP is more powerful, it’s free and it provides users with the ability to create new AutoCAD commands in minutes. This class helps seasoned AutoCAD users enter the world of customization and p programming g g using g AutoCAD's native g graphical p language. g g The class is designed for intermediate-level AutoCAD users who have never programmed in AutoLISP before.
You have come to the right place if... if • You know nothing or very little about Visual Lisp • You Y wantt tto write it your own Vi Visuall Lisp Li routines ti but b t have no idea where to begin. • You would like to have better control over your AutoCAD environment • You tried to “Walk down the Garden Path” but landed in a ditch! • You do not have a programming background
Objectives • To lay a firm foundation of the basics of Visual Lisp. Li • Prepare you to write your own Visual Lisp routines ti • Start you down the path to official AutoCAD G d Gurudom ( or “N “Nerdom”) d ”) • Teach you some quick and dirty basics of Visual Li (don’t Lisp (d ’t look l k too t close!). l !) • Discover new ways to torture your coworkers!
Hold on - we have a lot of information to cover in 80 minutes!
First and Foremost! Don’tt let Visual Lisp intimidate you! Don
What does LISP stand for? LISt Processor (not Lost In Stupid Parentheses!)
The Basics • • • •
Lists Functions Arguments Golden Rules of AutoLISP
Wh t iis a LIST? What Anything inside of parentheses Examples of LISTS: (a b c) (setq x 1) (princ)
What is a FUNCTION? (or subr) The ACTION you want Visual Lisp to do!
In Visual Lisp the function ALWAYS go first!!! Visual Lisp uses Prefix notation Example:
(+ 1 2) (- 5 3) (inters A B C D) (setq x 3)
Visual Lisp as a Calculator INFIX Notation (1 + 1) (3 * 4) (6 / 2)) PREFIX Notation (+ 1 1) ((* 3 4) (/ 6 2)
Arguments • Arguments are the values you pass to a f function ti (+ 5 6) + is the function g 5 and 6 are the arguments (setq x “Autodesk”) Autodesk ) Setq is the function X and “Autodesk” Autodesk are the arguments
The Golden Rules of Visual Lisp • For every open paren, you must have a closed l d paren Example: p ((setq q x (+ ( a b)) )) • For every open double quote, you must have a closed double quote. quote Example: (prompt “How are you?”)
The Key to unlocking complicated LISP routines: ti Visual Lisp p works from the Inside Out (+ 5 (* 4 3))
is equal to ( * 3) + 5 (4 (- (+ 5 2) (* 6 (- 7 6)))
i equall to is t ( + 2)) - ((6 * ((7 - 6)) (5 )) 7 - (6 * 1)
Quiz Time! Q
(* 4 (/ (+ 6 3) 3)) 12 (+ (* (- 5 2) (/ 15 3)) 6) 21 (/ (* (( 11 9) (+ ( 25 5)) (* 3 2)) 10
Some p popular p Data Types: yp • • • • •
Real Numbers Integers Strings Lists Subrs (or functions)
1.5 5 “LINE” (8 . “DIM”) SETQ
Real Numbers and Integers • Real Numbers have decimal points Example: 1.3 5.0 • Integers do not! Example: 25
11
• Real Numbers must have a leading zero. .5 5 is incorrect 0 5 is correct 0.5
D tt d pair: Dotted i (0 . “CIRCLE”) error: misplaced dot on input
(/ (/ (+ (+ (+
7 7 1 1 1
2) => 3 2.0) => 3.5 2 3 4 5 6. ) => 21.0 .5) 5) => invalid dotted pair 0.5) => 1.5
One real number changes the entire pot!
Basic Arithmetic Functions (for you math-heads): + = addition / = division (sqrt x) ( (expt t x y)) ((abs x)) (float x)
* = multiplication - = subtraction (sin ang) ( (cos ang)) ((log g x)) (fix x)
(atan x)
btw... btw
Angles are measured in radians! (not degrees) and you’ll need to remember that. that
St i Strings Usually Text (literals) Always double double-quoted quoted Spaces accepted
E Examples: l
““autodesk” t d k” “line” line “1.25”
Setting Variables (SETQ) (SETQ X 1) SETQ is the function X is the variable name 1 is the value Setting several variables at once: (SETQ A 1 B 2 C 3)
Variable Names • Alpha-numeric • May not contain spaces • should not replace existing preset values such h as T or pii
Note: A variable that hasn hasn’tt been set is equal to nil
Using Visual Lisp variables in AutoCAD (setq X 1 Y 2) Command: !X returns 1 C Command: d circle i l 3P/2P/TTR/ Center point>: 3P/2P/TTR/