This structure + 2 5 enclosed by parentheses, is called an expression and it is the basic structure for all AutoLISP programs. Everything intended for the AutoLISP interpreter, from the simplest expression to the most complex program, must be written with this structure. The result returned from evaluating an expression is called the value of the expression.
Variable
In your program you need to remember value given by the expression. you can do this by define a Variable. A Variable is like a container that holds a value. That value can change any time of a program's operation. You can create a Variable by Setq Function.
Understanding Data Types
Variables can take on several types of values or data types. Here is what some of these data types look like in AutoLiSP.
DATA TYPE |
EXAMPLE |
Integer |
24 |
Real Number |
0.618 |
String |
"India" |
List |
(4.5021 6.3011 0.0) |
File Descriptor |
<File: a620> |
Object Name |
<Object name: 60000014c> |
Selection Set |
<Selection set: 1> |
Symbols |
Point1 |
Subrs |
Setq |
Difference between Integer & Real No.
Integers are whole numbers from -32768 to + 32767. The value of an expression containing only integers is always give result an integer. on other hand Real numbers are numbers that include a decimal value. now try the following expression at command prompt.
(+ 75 12)
87
(+ 75.0 12.0)
87.0
do you notice the difference ? when you give only integer in AutoLisp expression it give result in Integer, but when you use real value it give result in Real Value. now try this expression
(+ .215 15)
the above expression looks perfectly normal, but the following error message appears:
error: invalid dotted pair
the real number 0.215 is preceded by a zero and not written as .215. In AutoLISP, real numbers with values between 1.0 and 0.0 must begin with zero. If you do not follow this rule, you will get an error message. remember this.
Strings
The term string refers to text. Strings are often used as prompts in AutoLISP expressions but they can also be manipulated using AutoLISP. For example, using the Strcat AutoLISP function, you could combine two strings, "My Name is" and "Dhimant Panchal", into one string "My Name is Dhimant Panchal". Try entering this:
(strcat "My Name is " "Dhimant Panchal")
The following is returned:
"My Name is Dhimant Panchal"
Lists
Lists are data elements enclosed in parentheses. They are the basic data structure in AutoLISP. A list can be made up of any number of integers, real numbers, strings, and even other lists.
There are two types of lists. An example of a list as a coordinate location. For example, the list
(5.0 10.0 20.0)
contains three elements, an X, Y, and Z coordinate. The first element, 5.0, is the x coordinate, the second element, 10.0 is the y coordinate, and the third element, 20.0, is the z coordinate.
We will learn about other type of data later.
Use Setq to assigne a Value to Variable
the setq function tells AutoLisp to assigne a value to variable. You can use alfabates, numbers or combination of alphabate & number as variable. there are no problem with upper case or lower case. for example VAR1 is equal to var1. try the following expression.
(setq Var1 1.500)
You can now obtain the value of a variable by preceding the variable name by an exclamation point. Now check the value of Var1
!Var1
the value 1.500 is returned.
Setq will assigne a value to the variable if the variable already has a value. try following.
(setq var1 1.500)
(setq var1 (+ var1 2.500))
the value 4.00 is returned.