Friday, May 23, 2014

Basic Concepts




Let's start with AutoLISP. It is used for writing programs for AutoCAD and CAD programs similar to AutoCAD. IntelliCAD is such a program.


With AutoLISP you can write programs that perform tasks and calculations automatically.


AutoLISP is a dialect of the programming language LISP. LISP has been developed by John McCarthy in the nineteen fifties.


LISP is the second higher programming language after FORTRAN. In the nineteen eighties LISP became really popular.


LISP was used for developing scientific systems, the so called Expert Systems, and systems for artificial intelligence.


Now we not only have LISP. There are also many dialects of LISP. Some dialects are InterLISP, MacLISP, ZetaLISP, CommonLISP, and SCHEME.


AutoLISP is also a dialect of LISP and it is based XLISP ODF David Bentz. AutoLISP looks very much like CommonLISP.


The name LISP comes from “LISt Programming” or LISt Processing”. It is also called “Lots of Insane Stupid Parenthesis”.


The Introduction Of AutoLISP



In AutoLISP you can write programs and functions that can be used in the AutoCAD program and CAD programs that are alternatives of AutoCAD.



Similar Programs


Autodesk started with the introduction of AutoLISP. They praised the:


- Flexibility
- Simplicity
- Interpretation


AutoLISP is flexible, because you define functions and programs in many ways. And variables can have many values.


AutoLISP is simple, because it is easy to learn. Of the higher programming languages AutoLISP is the easiest one to learn.


You can type an expression on the command prompt and right away you get to see the result. That is not complicated.


AutoLISP is being interpreted instead of being compiled. The advantage is that errors in the program can be found right away.


AutoLISP As A Tool


AutoLISP can be used as you are drawing in AutoCAD or an alternative CAD program. It can be used for making calculations. Or store data in memory.


Here is an example. Suppose you want to insert a block. And you want to insert it with a scale factor of three divided by seven.


The INSERT command is used. These are the prompts that show up at the command prompt:


- Command:
- Blockname:
- Insertion point:
- X scale factor:
- Y scale factor:
- Rotation angle:


We fill in the name of the block and we pick a point. That point is the insertion point. Now we must enter the scale factor.


We know the scale factor is three divided by seven. We could calculate what the value is and use the number.


The exact value is 0.4285714285714286. Maybe you round the value up to 0.43. But if you round it up, you do not get an exact value.


There is another way. It is the AutoLISP way. If you follow that way, you will use the exact value of the calculation.


At the prompt, where is asked for the X value, enter (/ 3.0 7.0). AutoLISP calculates the value and gives it back to the command.


Concepts


In AutoLISP there are the following concepts:


- Atoms
- Symbols
- Strings
- Real numbers
- Integers
- Subrs (built in functions)
- File descriptors
- AutoCAD entity names
- AutoCAD selection sets
- Lists


A symbol is a variable in which data is stored. Use a name that says something about the data that is stored in the symbol.


Example:


p1 - point
e1 - entity


A string is a text. In AutoLISP a string has got quotes. Here is an example of a string as is used in AutoLISP.


This is a string”


Real numbers have a value behind the point. Here are some real numbers:


- 3.24
- 14.9
- 15.0



An integer is a number without a part behind the point. Here are integers:


- 23
- 10


Subrs or built in functions are used by AutoLISP. They perform an action. Here are two examples:


+ - count
/ - divide


If you work with external files in AutoLISP, then
file descriptors are used. With the file descriptor the external file is specified.



Here is how a file descriptor may look:



<file #E814>



In an AutoCAD drawing you can find a lot of entities. Every line, circle, block, etc. is an entity.



These entities have a name. This is how the name of an entity may look:


<Entity name: 60000014>



In AutoCAD you may find selection sets. Selection sets are created by AutoLISP. They are named like this:
<Selection set:5>



These are the atoms of AutoLISP. But AutoLISP is also having lists. A list is a group of elements between brackets.


This is how a list may look:



- (A B C)
- (1 2 (3 4) 5)


A point is a list too. You can have 2D points and you can have 3D points. This is how they may look:



- 2D point: (10 20)
- 3D point: (10 20 30)


The numbers in the list for the point stand for the X value, the Y value, and the Z value. Only 3D points also have a Z value.


Functions


In AutoLISP there are a lot of functions. We have used a function as we were calculating a value for the INSERT command.


The function was (/ 3.0 7.0). Let's be more specific:


(/ 3.0 7.0) - list
/ - built in function
3.0, 7.0 - real numbers
/, 3.0, 7.0 - atoms


A call to a function is done with a list. You have seen what list has been used here. The first element is the symbol of the function.


The symbol of the function is the built in function. It is a dash. We have got a prefix notation. The symbol comes first.


You will find more functions in this book. They are all explained. I will not give you any more examples of functions.


Storing Data


We have used a function with the INSERT command. But the result of the function was not stored in the CAD program.


We can store data in the CAD program. The data is stored in a symbol. That is done with the SETQ function. Here is how it is done:


(setq vl 5)


The symbol VL gets the value five.


But if we use a function for a calculation, then the function gives back a value too. And we store that value in a symbol.


Here is what we can do with the function that we used with the INSERT command:


(setq dv (/ 3.0 7.0))


Now the value of three divided by seven is stored in the symbol DV.


Getting A Value


You have stored value in symbols. And now you want to know the values of the symbols. That is easy. Put an exclamation mark in front of the symbol.


We have used the SETQ function like this:



(setq vl 5)



To find the value that is stored in the symbol VL we enter “!vl” at the command prompt. And five is given back.



You could also enter at the command prompt:



(eval vl)


That function also gives back five.


Lexical Appointments


We were talking about AutoLISP. You saw the start of programming in AutoLISP. But there are some appointments to follow.


- For programing in AutoLISP lowercase characters and uppercase characters can be used. The use of lowercase characters is preferred.



- Symbol names can contain all characters except:


(
)
.
'

;


- The following characters end a symbol name:


(
)
'

;
(space)
(end of line)


- Symbol names and function names cannot start with a number.


- Texts are enclosed in quotes


- AutoLISP works with control codes. The following control codes are available:


\\ \ character
\e escape
\n new line
\r return
\t tab
\nnn character nnn


- You can place comments in an AutoLISP program by placing a semi colon in front of the colon. The AutoLISP program will ignore the comment.


- For symbols use a name of two characters. For functions use a name of five characters. To save computer memory.


Exercises


1. Is (1 4 “hallo”) a list?
2. Is '(1 2 3)' a list?
3. Is 21 a symbol?
4. How many elements has the list (1 45 (“this” “is”) “a text”)?
5. What is the integer of 3.1536?
6. What is the integer of 3.0?
7. Is point.1 a symbol?
8. Is point_1 as symbol?
9. What is the result of (setq ct 56 pt 23)
10. What character is placed in front of a symbol to get the value of the symbol?


Saturday, May 17, 2014

Introduction


Programming in AutoLISP is very easy. You may disagree. You may find it very complicated. Most people find it very complicated.


Are you working with the full version of AutoCAD? Or are you working with an alternative CAD program such as IntelliCAD or ZWCAD?


Use the 3P method for programming in AutoLISP. If you do, then you'll find programming in AutoLISP very easy.


Remember. Anything that is done by hand with an CAD program, can also be done by an AutoLISP program. Except AutoLISP is much faster.


The 3P method stands for:


- Planning
- Proces
- Programming


Here is a table in which an explanation is given:


Action
Description




Planning
What do you want the AutoLISP program to do?
Proces
What steps are to be undertaken by the AutoLISP program?
Programming
Write the AutoLISP program a function for each step.


Did you already figure out? If you follow the 3P method, then programming in AutoLISP becomes very easy. It isn't complicated at all.


In fact. Everything that is done in AutoCAD. Cvamn also be done with an AutoLISP program. Except AutoLISP is much quicker.


In this e-book there is talked about the basic concepts, the functions, the database, and the system variables.


At the end of the course an AutoLISP program is written. You figure out what AutoLISP program is to be written.


When the course has been completed you are ready to start programming in AutoLISP. Of course. If you need help. You can always contact me.


This is my e-mail address:


makeautocadfast@ymail.com




Saturday, May 10, 2014

Start

In my blog I offered my readers from Mislay that Iwould give them an AutoLISP course free of charge.That is how it was on March 14 this year.

I have 175 readers from Malaysia of my blog. But none of them came to me for the free AutoLISP 
course. I don't understand why.

Were they thinking I was offering a free AutoLISP course as as trick to get money from them? Nobody told me.

Sure. They had to pay me. I wanted them to pay me back my travel expenses. That is all. But was eventhat too much for them?

Anyway. I not only have readers of my blog from Malaysia. They come from all over the world. This iswhat I'm going to do.

I'm going to publish my AutoLISP course in this blog. And yes. It is free of charge. You don't have to pay me any money.

The course consists of the following twelve chapters. You will get them in the coming weeks. Every week you will get a chapter.

1.  Introduction 
2.  Basic Concepts 
3.  Arithmetic And Geometric Functions 
4.  Parametric Drawing 
5.  Predicates And Repeat Functions 
6.  Presentation Of Routines 
7.  List Functions 
8.  AutoLISP And AutoCAD Database 
9.  System Management
10.  System Variables 
11.  DXF Table 
12.  Answers 

At the end of each chapter there are exercises. The answers of the exercises will be given to you inthe last chapter.

This is only an AutoLISP course. But. Talking about AutoLISP. We also can deal with dialog boxes. 
That is next.

I will also publish a dialog boxes course. I will tell you later about the dialog boxes course. I 
will give you the chapters.