Programming References
Reference AutoCAD Help CAL Command for CAL syntax and functions.
Reference AutoCAD Developers Help for AutoLisp Developers Guide and Reference.
Complex Formula using Lisp Expressions - Example
AutoCAD provides a full Lisp programming language and debugger that can be very useful when developing complex Lisp expressions that will be used as formulas for Local and Mac Variables.
Here is an example of how you can use the Visual Lisp IDE ( VLIDE ) and the Macro Builder together to develop, debug and implement a complex Lisp expression in a Variable's formula.
Start the Macro Builder
Define the variables that will be used in an Lisp expression.
Four variables defined with different values.
Now, build a Lisp expression that will use these variables for a formula in a new variable.
Exit the Macro Builder
Start the Visual Lisp IDE
Start the Visual Lisp IDE by typing VLIDE at the AutoCAD command line.
Now you have AutoCAD and Visual LISP ( VLIDE ) in the system windows tray to choose from. You can select the needed program as you switch from one to the other.
In the Visual LISP Editor: Select File> New to open a new window for the Lisp code.
In the new untitled window define the variables you are going to use in Lisp. These are the same ones in the Macro Builder that you are going to use for a formula:
In the following lines define the Lisp expressions that define the formula. You can use any formatting you want for ease of reading:
The Lisp expression shown here reads as: IF Value1 > 35 THEN IF Value2 > 65 THEN 65 ELSE Value3 ENDIF ELSE IF Value3 > 50 THEN Value4 ELSE Value3 ENDIF ENDIF Result is 100 ( Value4 ) |
Evaluates as 100 ( Value4 ) |
Using the Lisp debugger you can set break points, display values of variables and run the code. Visual Lisp IDE has a full featured debugger. Once you have determined your code is good you can transfer it to the Macro Builder.
When the code is ready to use, select the lisp code you want and copy it by pressing Ctrl-C keys. In this case, every line in the lisp shown in the example start with the (if. The first several lines at the beginning that defined the variables are not used. They were just for debugging in Visual Lisp.
Note: Multi-Line expressions can not be typed directly into a Formula cell. It has to be copied and the pasted into the cell.
Select AutoCAD and type MAC to Start the Macro Builder ( VLIDE will temporarily be suspended )
In the Macro Builder define a new variable VALUE5. Tab to the formula cell. In the formula cell to the following:
• | First, press the = ( equal sign character ) in the formula field. This is required for Lisp expressions. |
• | Second, press Ctrl-V keys to Paste the Lisp code from Visual Lisp to the formula field. |
• | Third, press TAB to accept the cell edit. |
Press Accept button to accept the edits and evaluate the Macro.
Viewing the contents of the Formula cell with complex expressions
Normal Row Size |
Hover over the Formula Cell |
Expanded Row Height and Width |
The formula field supports formatted multi-line text when pasted. You can not type a multi-line text directly into the Formula field.
Character limit of the Formula cell is 1024 characters.