lisp legal
TRANSCRIPT
-
7/31/2019 Lisp Legal
1/52
-
7/31/2019 Lisp Legal
2/52
Objectives
To lay a firm foundation of the basics of VisualLisp.
Prepare you to write your own Visual Lisproutines
Start you down the path to official AutoCADGurudom ( or Nerdom)
Teach you some quick and dirty basics of VisualLisp (dont look too close!).
Discover new ways to torture your coworkers!
-
7/31/2019 Lisp Legal
3/52
Hold on - we have a lot of information tocover in 80 minutes!
-
7/31/2019 Lisp Legal
4/52
First and Foremost!Dont let Visual Lisp intimidate you!
-
7/31/2019 Lisp Legal
5/52
What does LISP stand for?
LISt Processor
(not Lost In Stupid
Parentheses!)
-
7/31/2019 Lisp Legal
6/52
The Basics
Lists
Functions
Arguments Golden Rules of AutoLISP
-
7/31/2019 Lisp Legal
7/52
What is a LIST?
Anything inside of parentheses
Examples of LISTS:
(a b c)
(setq x 1)
(princ)
-
7/31/2019 Lisp Legal
8/52
What is a FUNCTION?
(or subr)The ACTION you want Visual Lisp to do!
-
7/31/2019 Lisp Legal
9/52
In Visual Lisp the function ALWAYSgo first!!!
Visual Lisp uses Prefix notation
Example: (+ 1 2)(- 5 3)
(inters A B C D)
(setq x 3)
-
7/31/2019 Lisp Legal
10/52
Visual Lisp as a Calculator
INFIX Notation(1 + 1)
(3 * 4)
(6 / 2)PREFIX Notation
(+ 1 1)
(* 3 4)
(/ 6 2)
-
7/31/2019 Lisp Legal
11/52
Arguments
Arguments are the values you pass to afunction
(+ 5 6)
+ is the function
5 and 6 are the arguments
(setq x Autodesk)
Setq is the functionX and Autodesk are the
arguments
-
7/31/2019 Lisp Legal
12/52
The Golden Rules of Visual Lisp
For every open paren, you must have aclosed paren
Example: (setq x (+ a b))
For every open double quote, you must
have a closed double quote.
Example: (prompt How are you?)
-
7/31/2019 Lisp Legal
13/52
The Key to unlocking complicatedLISP routines:
Visual Lisp works from the Inside Out(+ 5 (* 4 3))
is equal to
(4 * 3) + 5(- (+ 5 2) (* 6 (- 7 6)))
is equal to
(5 + 2) - (6 * (7 - 6))
7 - (6 * 1)
-
7/31/2019 Lisp Legal
14/52
Quiz Time!
(* 4 (/ (+ 6 3) 3))12
(+ (* (- 5 2) (/ 15 3)) 6)21
(/ (* (- 11 9) (+ 25 5)) (* 3 2))
10
-
7/31/2019 Lisp Legal
15/52
Some popular Data Types:
Real Numbers 1.5
Integers 5
Strings LINE Lists (8 . DIM)
Subrs (or functions) SETQ
-
7/31/2019 Lisp Legal
16/52
Real Numbers and Integers
Real Numbers have decimal pointsExample: 1.3 5.0
Integers do not!
Example: 25 11
Real Numbers must have a leading zero.
.5 is incorrect 0.5 is correct
Dotted pair: (0 . CIRCLE)
error: misplaced dot on input
-
7/31/2019 Lisp Legal
17/52
(/ 7 2) => 3
(/ 7 2.0) => 3.5(+ 1 2 3 4 5 6. ) => 21.0
(+ 1 .5) => invalid dotted pair
(+ 1 0.5) => 1.5
One real number changes the entire pot!
-
7/31/2019 Lisp Legal
18/52
Basic Arithmetic Functions(for you math-heads):
+ = addition * = multiplication
/ = division - = subtraction
(sqrt x) (sin ang) (atan x)
(expt x y) (cos ang)
(abs x) (log x)
(float x) (fix x)
-
7/31/2019 Lisp Legal
19/52
btw...
Angles are measured in radians!
(not degrees)
and youll need to remember that.
-
7/31/2019 Lisp Legal
20/52
Strings
Usually Text (literals)
Always double-quoted
Spaces accepted
Examples: autodesk
line
1.25
-
7/31/2019 Lisp Legal
21/52
Setting Variables
(SETQ)
(SETQ X 1)
SETQ is the functionX is the variable name
1 is the value
Setting several variables at once:(SETQ A 1 B 2 C 3)
-
7/31/2019 Lisp Legal
22/52
Variable Names
Alpha-numeric
May not contain spaces
should not replace existing preset valuessuch as T or pi
Note: A variable that hasnt been set isequal to nil
-
7/31/2019 Lisp Legal
23/52
Using Visual Lisp variables inAutoCAD
(setq X 1 Y 2)
Command: !Xreturns 1
Command: circle
3P/2P/TTR/:
Diameter/:!Y
-
7/31/2019 Lisp Legal
24/52
Ways to ruin your Visual Lisp life
(setq + -)
(setq * /)
(setq pi 2.5)
Visual Lisp will let you abuseyourself. . .
-
7/31/2019 Lisp Legal
25/52
Using AutoCAD commandsin Visual Lisp (the good stuff!)
Using the COMMAND function, you canaccess the AutoCAD commands
Example:(command QSAVE)
(command TRIM)
(command ZOOM P)
(command LAYER)
B d f lt Vi l Li d t
-
7/31/2019 Lisp Legal
26/52
By default, Visual Lisp doesntdisplay dialog boxes
Visual Lisp displays the command line interfacefor commands.
To force the dialog box use:(initdia)
Before the command:
(initdia)
(command layer)
-
7/31/2019 Lisp Legal
27/52
pause allow for user input
(command) cancel
enter
-
7/31/2019 Lisp Legal
28/52
(Command ZOOM A)
(Command ERASE L )
(Command INSERT DESK pause 1 1 pause)
(Command LINE A B C C)
(Command TEXT pause .5 0 Visual Lisp)
(Command LAYER S pause )(Command)
-
7/31/2019 Lisp Legal
29/52
Creating your own AutoCAD
Commands(DEFUN)DEFUN binds a set of expressions to a
variable.
(DEFUN C:ZAP ( )
Command: zap
-
7/31/2019 Lisp Legal
30/52
DEFUN
is the function
C:indicates the function will be an
AutoCAD command
( )indicates no local variables and noarguments (well get to that another
time!)
Anatomy of DEFUN
-
7/31/2019 Lisp Legal
31/52
DEFUN examples
(DEFUN C:ZA ( )
(Command ZOOM A)
)
(DEFUN C:SQ ( )(Command POLYGON 4 E pause pause)
)
(DEFUN C:ZAP ( )
(Command erase all ))
S O S
-
7/31/2019 Lisp Legal
32/52
SHORT.LSP(defun c:ls ( )(command layer M pause )
)
(defun c:ZO ( )
(command ZOOM O)
)
(defun c:ttr ( )(command circle ttr pause pause pause)
)
(defun c:Jellydonut ( )(command donut 0 pause )
)
-
7/31/2019 Lisp Legal
33/52
Loading Visual Lisp routines
APPLOAD - used to load one or more VisualLisp routines
(load short)
-
7/31/2019 Lisp Legal
34/52
Opening a dialog to a specific tab
(command +dialogname X)
(command +options 7)will open the Options dialog to tab #8
(command +customize 0)
-
7/31/2019 Lisp Legal
35/52
Whats wrong with this picture?
(defun c:door
(insert door pause 1 1 45)
)(defun c:fun ())
(prompt are we having fun yet?)
)
-
7/31/2019 Lisp Legal
36/52
PPurge.LSP
(Defun c:ppurge ( )
(command purge all * N))
Lets create a command that
-
7/31/2019 Lisp Legal
37/52
Lets create a command thatbreaks an object in the same
spot twice(defun c:crack ()
-
7/31/2019 Lisp Legal
38/52
Clean up your ACT!
PRINC (get rid of the nils!)
-
7/31/2019 Lisp Legal
39/52
PPurge.LSP
(Defun c:ppurge ( )
(command purge all * N)(princ)
)
Just for fun!
-
7/31/2019 Lisp Legal
40/52
Just for fun!
ALERT
ALERT sends an ALERT box to the screenwith the indicated text
Example:
(ALERT Formatting the hard drive)
-
7/31/2019 Lisp Legal
41/52
ACAD.LSP or ACADDOC.LSPAutomatic Visual Lisp Loading
Put frequently used Visual Lisp routines.
Undefine those AutoCAD commands youwant to automatically replace with VisualLisp routines.
Place partial menu loading instructions
-
7/31/2019 Lisp Legal
42/52
ACAD.LSP
(defun c:ZA ( )(command Zoom All)(princ))
(defun c:DT ( )
(setvar clayer TEXT)(command Dtext)(princ))
(defun c:bolt ( )(command insert bolt pause pause pause)(princ))
-
7/31/2019 Lisp Legal
43/52
Automatic loading LISP files
ACAD.LSP 2
ACADDOC.LSP 4
ACAD.MNL 5-------------
ACAD200X.LSP 1
ACAD200XDOC.LSP 3
-
7/31/2019 Lisp Legal
44/52
Undefine and Redefine
Permits undefining and redefining theinternal AutoCAD commands
Note: AutoCAD commands can always beexecuted with a leading period.
S STARTUP
-
7/31/2019 Lisp Legal
45/52
S::STARTUPa special section of ACAD.LSP
(defun C:LINE ( )(prompt Shouldnt you be using Polylines?)
(command PLINE))
(defun S::STARTUP ( )(command undefine line)
)
Note: s::startup is the last file to be loaded beforecontrol is handed over to the user.
-
7/31/2019 Lisp Legal
46/52
Ways to torture your coworkers:
ACAD.LSP
(defun c:qsave ( )(command undo b y)
(command .qsave .qsave)(defun s::startup ()
(command undefine save)(command undefine qsave)(command undefine saveas)
)
-
7/31/2019 Lisp Legal
47/52
one more means of torture:
(defun c:zoom ( )
(command erase L )
(command .zoom)
(princ)
)(defun c:redo ( )
(prompt You goofed - deal with it!)
)
(defun c:undo ( )(alert Get it right the first time!)
-
7/31/2019 Lisp Legal
48/52
(defun c:regen ()
(setvar cmdecho 0)
(command donut 0 300000000000 10,10)
(command regen)
(command cmdecho 1)
)(defun s::startup ( )
(command undefine zoom)
(command undefine undo)(command undefine redo)
(command undefine regen)
)
Other evil things to put in
-
7/31/2019 Lisp Legal
49/52
Other evil things to put ins::startup!
S::STARTUP
(setvar angbase 180)
OR
(setvar snapang 0.000001)
OR
(command vpoint 0,0,-1)(command ucsicon off)
-
7/31/2019 Lisp Legal
50/52
Whats wrong with this picture?
(1 + 1)(* 5 .25)
(/ 9 2)
(setq x (+ 1 2)
(defun d:dimwit
(command text .5 90 pause)
(alert hit cancel to exit dialog box)
(defun s:startup ( )
-
7/31/2019 Lisp Legal
51/52
Review
LISP stands for. . .
List
Function
Command pause
DEFUN
(princ) ( )
undefine
Acad.lsp
s::startup
string
-
7/31/2019 Lisp Legal
52/52
Lynn Allen
Lynns Blog
www.autodesk.com/blog
mailto:[email protected]://www.autodesk.com/bloghttp://www.autodesk.com/blogmailto:[email protected]