AutoLISP Tutorials
By barryrbowen
AutoLISP Expressions
AutoLISP was first implemented in AutoCAD v2.15, in the form of “Variables and Expressions.” There are many ways to increase your productivity when using AutoCAD and writing your own AutoLISP programs can be an easy one to implement. This feature, built right inside AutoCAD, offers an amazing amount of utility without requiring any programming experience.
Variables and expressions provide the ability to create parametric menu macros and scripts. This article will discuss some of the AutoLISP expressions and how they can be used at the AutoCAD command line.
All AutoLISP expressions are enclosed in parentheses. A valid expression must begin with an open parenthesis and every open parenthesis must be balanced by a closing parenthesis. Otherwise, the AutoCAD LISP interpreter (that portion of AutoCAD that evaluates and executes the AutoLISP functions) will respond with an error message. If you ever see the response “1>” or “(_>” after trying an AutoLISP expression, AutoCAD is telling you that you omitted one or more closing parenthesis.
At its simplest, you can perform addition, subtraction, multiplication, and division using simple numbers and arithmetic operators directly from the AutoCAD command line:
Command: (+ 1 2 3)
6
Command: (* 2.5 2)
5.000000
Command: (+ (* 3 2) 4)
10
In AutoLISP, the operator precedes the values being operated upon, much like Reverse notation of the early Hewlett Packard calculators. Notice also that AutoLISP evaluates from the innermost parentheses outward. You can use an AutoLISP expression to provide the response in the middle of an AutoCAD Command prompt:
Command: CIRCLE
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: 5,5
Specify radius of circle or [Diameter]: (/ 10.0 2.0)
In the beginning, these examples might not appear very useful, but AutoLISP is a powerful programming language built within AutoCAD, that brings supercomputer power to your drafting needs. With AutoLISP any repetitive task can usually be automated to reduce time or improve accuracy. I believe that anything you can draw manually in AutoCAD can be automated by writing an AutoLISP/Visual LISP program.
Comments
No comments yet.