AutoLISP Lesson #2 - THE AutoLISP ENVIRONMENT: Data types Function : is the first item in every list. The remainder of the list is used as the parameters or arguments to the function. If the first item in the list is not a function you will receive an error message stating: "bad function."Symbol: is what other programming languages call a variable, and from this point on when I refer to a variable I am really talking about a symbol. A symbol in LISP however can be a whole lot more than just a value, as a normal variable would hold. A symbol can contain a list or a function definition. A symbol has a value bound to it. If it has no binding it is said to be"nil". All symbols should be set to nil upon ending a program or encountering an error. List : is anything that is not a symbol.Errors Special characters
( ) ' " ;
\\ Gives a normal backslash character. \" Gives a normal double quote character. \e Gives an escape character. \n Gives a new line character. \r Gives a return character. \t Gives the tab character. \nnn Gives a character who’s octal code is nnn.
'This is equivalent to (quote this)
; This is a comment Comments will be discussed in depth later in the lessons. The LISP interpreter
The current bindings of functions and variables can be retrieved at the command line by using the exclamation character "!". If the value being retrieved is a function the entire function list will scroll across the screen. If the value being retrieved is a variable, the value of the current binding will be returned. This is normally what you are after when you check the current binding of an object. When checking for errors in code it is sometimes helpful to see that your variables are getting set correctly. Command functions (defun c:function_name ( / ) The function can be called within AutoCAD without having to put parenthesis around it. The "c:" has nothing to do with your disk drives; it merely tells LISP that the function should be defined as a command line function. Lisp libraries If you have certain things you do every time you enter a drawing, they can be added to the ACAD.LSP file and automatically executed every time the ACAD.LSP file is loaded. To do this you must define a function that is called "s::startup". The s::startup function is executed every time ACAD.LSP is loaded. Any lisp function may be loaded by typing (load "lispname"). The command must be inside parenthesis, and the ".lsp" extension should not be added. If you find your lisp programs will not load, make sure you have followed the rules above, then try what comes next. AutoLISP will search the support file search path that is set in the CONFIG command. If it doesn't find your program the search path it will not load it and will tell you it couldn't find it. It will list all the places it looked. If your file is not in a search path, and can't be put there, you can still load it by giving AutoLISP the entire path to the file in the load command, example: (load "c:/acad/dave/myprog") Note I used forward slashes instead of back slashes. AutoLISP will not interpret back slashes correctly if you only use (1) one. Remember from earlier in the lesson the back slash is a special character in AutoLISP and cannot be used in the literal use. Also remember that it can be used literally if you put (2) two in a row. Like this: (load "c:\\acad\\dave\\myprog") |
|