Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
AutoLISP
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== A simple [[Hello world program]] in AutoLISP would be: <syntaxhighlight lang="lisp" line> (defun hello ( ) (princ "\nHello World!") (princ) ) </syntaxhighlight> Note the final line inside the function definition: when evaluated with no arguments, the <code>princ</code> function returns a null symbol, which is not displayed by the AutoCAD [[command-line interface]]. As the AutoCAD command line functions as a [[read–eval–print loop]] (REPL), this would normally print "Hello World!" to the command line, followed immediately by the return value of the call to <code>princ</code>. Therefore, without the final call to the <code>princ</code> function, the result of this would be: :<code>Hello World!"\nHello World!"</code> The <code>prin1</code> function may also be used to achieve the same result. A more complex example is: <syntaxhighlight lang="lisp" line> (defun c:pointlabel ( / pnt ) (if (setq pnt (getpoint "\nSpecify point: ")) (progn (entmake (list '(0 . "POINT") (cons 10 (trans pnt 1 0)) ) ) (entmake (list '(0 . "TEXT") (cons 10 (trans (cons (+ (car pnt) 0.6) (cdr pnt)) 1 0)) (cons 40 (getvar 'textsize)) (cons 1 (strcat "X:" (rtos (car pnt)) " Y:" (rtos (cadr pnt)))) ) ) ) ) (princ) ) </syntaxhighlight> The above code defines a new [[Subroutine|function]] which generates an AutoCAD point object at a given point, with a one-line text object displaying the X and Y coordinates beside it. The name of the function includes a special prefix 'c:', which causes AutoCAD to recognize the function as a regular command. The user, upon typing 'pointlabel' at the AutoCAD command line, would be prompted to pick a point, either by typing the X and Y coordinates, or clicking a location in the drawing. The function would then place a marker at that point, and create a one-line text object next to it, containing the X and Y coordinates of the point expressed relative to the active User Coordinate System (UCS). The function requires no [[Parameter (computer programming)|parameters]], and contains one [[local variable]] ('pnt'). The above example could also be written using built-in AutoCAD commands to achieve the same result, however this approach is susceptible to changes to the command prompts between AutoCAD releases.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)