Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
AutoLISP
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
AutoLISP
(section)
Add topic