Saturday, December 20, 2014

AutoLISP Program For Free

AutoLISP Program For Free


Yeah. You have read it right. You can get an AutoLISP program. Tell me what program you want and I write it for you. For free.


You Know About AutoLISP Programs


You know about AutoLISP programs. They help you to speed up AutoCAD. Or a CAD program that is an alternative for AutoCAD.


I'm not talking about free CAD programs. I'm talking about CAD programs that you must pay for. IntelliCAD is such a program.


You think that is very good. And you know you can engage me to write an AutoLISP program for you. But you are not sure.


Engaging Me


You are thinking. When you engage me to write an AutoLISP program, you must pay me. You are wondering. How much must you pay me?


Well. This is how it is. You engage me for writing an AutoLISP program and you don't have to pay me. I will write it for free.


Catch


Is there a catch? Oh yes. There is a catch. But don't feel that you are forced to pay me. It is all up to you.


I works like this. You tell me what AutoLISP program you want and I write the program for you. You will get the program.


Work with the program. See how it is. Do you feel your CAD program is quicker? Do you feel you are saving money with the program?


Up To You


If you feel that your CAD program is quicker and that you are saving money, then make a calculation. What is the value?


You can pay me the value off the AutoLISP program. But it is up to you. Only pay me if you want to pay me. Pay me what you feel is right.



















Friday, December 5, 2014

ACAD.LSP

ACAD.LSP


ACAD.LSP is a special file of AutoCAD. It is automatically loaded as you start a new drawing. And what is in it, is performed.


Loading AutoLISP Files


Suppose you have a program, that you are using all the time. You can specify in the ACAD.LSP file that that program is loaded.


Add this line to the ACAD.LSP file:


(load “-/-----/-----.lsp”)


And the program is loaded as a new drawing is started. Just enter the name of the AutoLISP program, to start it.


You can even specify the complete AutoLISP program in ACAD.LSP. If you do, the AutoLISP program is load into AutoCAD automatically.


Global Variables


Maybe you are working with global variables. That could be variables of your own or AutoCAD. You can set their value here.


Giving Information


Or maybe you want to give information to the user at the start of a new drawing. Have a line that starts with PRINC.


You could add a line like this:


(princ “\n---------------------------”)


IntelliCAD


Maybe you are not working with AutoCAD. Maybe you are working with IntelliCAD. You will not find ACAD.LSP in IntelliCAD.


But IntelliCAD has got ICAD.LSP. In IntelliCAD that file has got the same function as the ACAD.LSP file in AutoCAD.


Other AutoCAD Alternatives


There are more alternatives for AutoCAD. And those alternatives do not have the ACAD.LSP file. But you can look for a similar file.



In Windows do a search for LSP. You will see the file that is used as ACAD.LSP is used. Open the file and see for yourself.

Sunday, November 16, 2014

Symbol Tables

Symbol Tables


There are symbol tables in AutoCAD. Through AutoLISP you have access to the symbol tables. You can get information from them.


But that is not possible. There are no functions for changing the information of the symbol tables. You can only get information from them.


Types Of Symbol Tables


The following types of information tables are available:


- Line types
- Layers
- Text styles
- Views
- User Coordinate System
- Viewport Configuration
- Blocks


Two functions are available for getting information from the symbol tables:


Functions
Use




TBLNEXT
Scanning the symbol tables
TBLSEARCH
Searching in the symbol tables


TBLNEXT


(tblnext <table name> <start>)


The first argument gives the name of the symbol table. These names are valid:


- LTYPE
- LAYER
- STYLE
- VIEW
- UCS
- VPORT
- BLOCK


When the TBLNEXT function is used all the time, then the next symbol is displayed. The function works with its own pointer.


When the START argument is present and it is true or T, then the function all the time starts at the beginning of the table.


If the START argument is not present or it has got a value of nil, then all symbols are displayed. At the end the function gives back nil.


The result of the TBLNEXT function is a dotted pair list, very much like the entity list from an entity.


Example:


(tblnext "layer" T)


may give:


(
(0 . "layer") - symbol type
(2 . "0") - symbol name
(70 . 0) - flags
(62 . 7) - color number
(6 . "continuous") - name line type
)


(tblnext "block")


(
(0 . "block") - symbol type
(2 . "cadre") - symbol name
(70 . 0) - flags
(12 . 100.0 100.0 0.0) - insertion point
(-2 . <Entity name: 40000136) - first entity block
)


When dealing with a block, then you find the -2 group in the definition. In the example we have the block with the name CADRE.


TBLSEARCH


(tblsearch <table name> <symbol> <follow>)


The function searches in the table name for the symbol with the name. If the symbol is found, then a dotted pair is given back.


Example:


There is searched for a text style with the name STANDARD. This is how it is done and this is what can be given back.


(tblsearch "style" "standard")


This can be given back:


(
(0 . "STYLE") - symbol type
(2 . "STANDARD") - symbol name
(70 . 0) - flags
(40 . O.O) - text height
(41 . 1.0) - width factor
(60 . 0.0) - angle
(71 . 0) - gewwnerate flags
(3 . "TXT") - font file
(4 . "") - big font file
)


Here is another example. Now there is searched for the the block with the name VALVE in the BLOCK symbol table.


(tblsearch "block" "valve")


This is given back:


(
(0 . "BLOCK")
(330 . <Entity name: 36dafb0>)
(67 . 0)
(8 . "0")
(62 . 256)
(6 . "ByLayer")
(370 . -1)
(347 . <Entity name: 0>)
(284 . 0)
(48 . 1.00000)
(60 . 0)
(70 . 0)
(10 0.000000 0.000000 0.000000)
(-2 . <Entity name: 372c048>)
(2 . "valve")
(1 . "")
(4 . "")
(280 . 1)
(281 . 0)
)


The TBLSEARCH function also works with a pointer. But the pointer is not of influence of the pointer from the TBLNEXT function. Unless it it T.




















Saturday, November 1, 2014

Symbol Tables

Symbol Tables


There are symbol tables in AutoCAD. Through AutoLISP you have access to the symbol tables. You can get information from them.


But that is not possible. There are no functions for changing the information of the symbol tables. You can only get information from them.


Types Of Symbol Tables


The following types of information tables are available:


- Line types
- Layers
- Text styles
- Views
- User Coordinate System
- Viewport Configuration
- Blocks


Two functions are available for getting information from the symbol tables:


Functions
Use




TBLNEXT
Scanning the symbol tables
TBLSEARCH
Searching in the symbol tables


TBLNEXT


(tblnext <table name> <start>)


The first argument gives the name of the symbol table. These names are valid:


- LTYPE
- LAYER
- STYLE
- VIEW
- UCS
- VPORT
- BLOCK


When the TBLNEXT function is used all the time, then the next symbol is displayed. The function works with its own pointer.


When the START argument is present and it is true or T, then the function all the time starts at the beginning of the table.


If the START argument is not present or it has got a value of nil, then all symbols are displayed. At the end the function gives back nil.


The result of the TBLNEXT function is a dotted pair list, very much like the entity list from an entity.


Example:


(tblnext "layer" T)


may give:


(
(0 . "layer") - symbol type
(2 . "0") - symbol name
(70 . 0) - flags
(62 . 7) - color number
(6 . "continuous") - name line type
)


(tblnext "block")


(
(0 . "block") - symbol type
(2 . "cadre") - symbol name
(70 . 0) - flags
(12 . 100.0 100.0 0.0) - insertion point
(-2 . <Entity name: 40000136) - first entity block
)


When dealing with a block, then you find the -2 group in the definition. In the example we have the block with the name CADRE.


TBLSEARCH


(tblsearch <table name> <symbol> <follow>)


The function searches in the table name for the symbol with the name. If the symbol is found, then a dotted pair is given back.


Example:


There is searched for a text style with the name STANDARD. This is how it is done and this is what can be given back.


(tblsearch "style" "standard")


This can be given back:


(
(0 . "STYLE") - symbol type
(2 . "STANDARD") - symbol name
(70 . 0) - flags
(40 . O.O) - text height
(41 . 1.0) - width factor
(60 . 0.0) - angle
(71 . 0) - gewwnerate flags
(3 . "TXT") - font file
(4 . "") - big font file
)


Here is another example. Now there is searched for the the block with the name VALVE in the BLOCK symbol table.


(tblsearch "block" "valve")


This is given back:


(
(0 . "BLOCK")
(330 . <Entity name: 36dafb0>)
(67 . 0)
(8 . "0")
(62 . 256)
(6 . "ByLayer")
(370 . -1)
(347 . <Entity name: 0>)
(284 . 0)
(48 . 1.00000)
(60 . 0)
(70 . 0)
(10 0.000000 0.000000 0.000000)
(-2 . <Entity name: 372c048>)
(2 . "valve")
(1 . "")
(4 . "")
(280 . 1)
(281 . 0)
)


The TBLSEARCH function also works with a pointer. But the pointer is not of influence of the pointer from the TBLNEXT function. Unless it it T.




















Friday, October 24, 2014

Selection Set Functions

Selection Set Functions


You can work with selection sets. A selection set can be used to perform a command like MOVE. Entities are put in a selection set.


These are the selection sets:


Selection
Set
Use




SSGET
Creating a selection set
SSLENGTH
Number of entities in a selection set
SSNAME
Name of an entity of a selection set
SSADD
Adding an entity to a selection set
SSDEL
Deleting an entity from a selection set
SSMEMB
Checking if an entity is in a selection set


SSGET


This is the syntax of the fucntion:


(ssget [<mode>] [<point1> [<point2>]])


Let's talk about the modes of the SSGET function. There are seven modes. Here is how the modes are used.


For the selection of selection sets temporary files of AutoCAD are used. That is why no more than six selection sets can be open.


Mode
Description




(ssget)
The user is asked to make selection. This is the prompt that shows up:


Select entities:
(ssget “p”)
The previous selection set is selected.
(ssget “l”)
The last entity is selected.
(ssget <point>)
The enity going through the point is selected.
(ssget “w”
<point1> <point2>)
The entities in the window from point1 and point2 are selected.
(ssget “c”
<point1> <point2>)
The entities in the crossing point1 and point2 and the ones touching the crossing are selected.
(ssget “x”
<filter-list>
)
The entities in confirmation with the filter list are selected.


Let's talk about a filter list. In the filter list you can specify which entities are to be selected and put into the selection set.


Here is how the qualities of entities can be selected.


Number
Description




0
Entity type
2
Block name
6
Line type name
7
Text style name
8
Layer name
38
Elevation
39
Thickness
62
Color number
66
Attributes number
210
3D extrusion


Here is an example of how a filter list could be used. Suppoase you want to select all lines on the layer FLOOR and having the color yellow.


(ssget “x” (list (cons 0 “line”) (cons 8 “floor”) (cons 62 “2)


SSLENGTH


After you have created a selection set, then this has been created:


<Selection set: 58697680>


It doesn't tell you how many entities are in the selection set and it doesn’t tell you what entities are in the selection set.


You can find out how many entities there are in the selection set. To do so, use the SSLENGTH function. Used it like this:


(sslength ss)


The variable of the selection set is SS.


SSNAME


But now you want to know the names of the entities that are in the selection set. You can do so by using the SSNAME fucntion.


But take care. First find out the length of the selection set with the SSLENGTH function. And then you can find the names of the entities.


But take care. The index of the first entity is 0. So if the length of the selection set is five, then the indexes are 0, 1, 2, 3, and 4.


Suppose we hhave a selection set and we want to know the nakme oif the first entity. This is how we find it:


(ssname ss 0)


The name of the entity is given back. The name may look like:


<Entity name: 19ef010>


If you want to know more about the entity, use the ENTGET function. The ENTGET function gives back the entity list.


SSADD


You have created a selection set. And now you want to add an entity to the selection set. This is how it is done.


(ssadd et ss)


ET is the variable of the entity that is to be added and SS is the variable that has the selection set.


SSDEL


Now you have a selection set. But you want to remove one entity from the selection set. Do it like this:


(ssdel et ss)


SSMEMB


You wat to be sure that certain entity is a member of the selection set. Use the SSMEMBER function for finding out. Like this:


(ssmemb et ss)


In the example ET is the entity that is to be checked for being in the selection set. The selection set is SS.


If ET is not in the selection set, then NIL is given back. Otherwise the name of the entity is given back.












Friday, October 17, 2014

Entity Functions

Entity Functions


You are drawing in AutoCAD. Everything that has been drawn is called an entity. So a line is an entity, or a circle.


There are functions that deal with entities. Here is a list of those functions:


Function
Description




entdel
Delete an entity from the AutoCAD database
entget
Getting the entity list
assoc
Getting a part list of the entity list
cons
Creating a part list
subst
Changing an entity list
entmod
Update an entity list
entupd
Update sub entities


ENTDEL


This function can undertake two actions. It deletes an entity from the AutoCAD database or it places it back in the database.


This is how it looks:


(setq e2 (entnext e1))


(entdel e2) - E2 is deleted
(entdel e2) - E2 is placed back


Take care. An entity is only placed back if it has been removed in the drawing session. Once the drawing is saved, it is gone permanently.


ENTGET


We have the name of an entity. And we want to get the entity list. To get a specification of the entity. This is how it is done:


(setq e2 (entnext e1))
(setq el (entget e2))


This is what is given back by the ENTGET function:


((-1 . <Entity name: 36c23b8>) (0 . "LINE") (5 . "1C5") (67 . 0) (8 . "0") (62 . 256) (6 . "ByLayer") (370 . -1) (347 . <Entity name: 0>) (284 . 0) (48 . 1.00000) (60 . 0) (39 . 0.000000) (10 -6.82195 26.1188 0.000000) (11 47.4674 7.08229 0.000000) (210 0.000000 0.000000 1.00000))


The entity list gives the following information among other information:


- The entity is a LINE
- The handle of the entity is IC5
- The layer of the entity is 0
- The start point is (-6.82195 26.1188 0.000000)
- The end point is (47.4674 7.08229 0.000000)


ASSOC


This function gives back the part list of an entity list. You need to give the key of the entity list to get the part list.


This is how it looks. We use the previous entity list. The variable of the entiy lsit is EL.


Function
Gives back




(assoc 0 el)
(0 . "LINE")
(assoc 5 el)
(5 . "1C5")
(assoc 10 el)
(10 -6.82195 26.1188 0.000000)
(assoc 11 el)
(11 47.4674 7.08229 0.000000)


Suppose you want to know the exact location of the start point. You can find it like this:


(cdr (assoc 10 el))


CONS


This function constructs a part list. Maybe you want to change an existing entity list with the SUBST function.


Here is how the CONS function can be used:


Function
Given back




(cons 8 “Floor”)
(8 . "Floor")
(cons 10 (list 100 10 0))
(10 100 10 0)


There can be a point or a space between the two elements.


SUBST


You have an entity. You want to make changes to the entity. You can do it by using this function. Here is the syntax.


(subst <new item> <old item> <entity list>)


Old item and new item are part lists of the entity list.


Here is an example of how this function can be used. We start with the entity list from before. We want to change the layer of the entity.


(subst (cons 8 “floor”) (assoc 8 el) el)


E2 is the variable that contains the entity list.


There is one problem. If you change the entity list like that, it is not shown in the screen. But it can be shown.


Use the ENTDEL function two times. The first time the entity is deleted and the second time the entity is displayed again.


When it is displayed again, then the changed entity list is used. And the entity is moved to the layer that is specified.


ENTMOD


With the ENTMOD function an entity list can be written to the AutoCAD database again. The entity list is updated.


ENTUPD


The ENTUPD function can be used to have changes of an entity being made in the screen.




Friday, October 10, 2014

AutoCAD Database


AutoCAD has got a database. In it all entities are stored and the properties of all entities. With AutoLISP you can change the properties.


Later youi will see how that is done. For now let's talk about the AutoCAD database. The AutoCAD database consists of five parts:


- Header
- Tables
- Blocks
- Entities
- End of file


Header


Contains general information about the drawing such as the values of all the system variables.


Tables


This part contains information about:


- Line types
- Layers
- Text styles
- Views
- User Coordinate System
- Viewport configuration
- Drawing manager


Blocks


Here you find all information of the blocks that can be found in the drawing.


Entities


Here are all the information about the entities in the drawign, block references included.


End of file


Indication the the end of the file has been reached.


Entities


Examples of entities are:


- Line
- Circle
- Arc
- Polyline
- Text
- Solid
- Point


Let's be more specific. This is the information about a line that can be found in the AutoCAD database.


- Entity type: line
- Layer
- Color
- Start point of line
- End point of line
- Linetype


From other entities different information can be found. But that is important. You can change the information with AutoLISP.


AutoCAD Database Structure


When an entity is created in AutoCAD, it get a number. And example of such a number is:


<Entity name: 3774828>


The name doesn't say what type of entity it is. The entity could be a line, a circle, an arc, a polyline, or a text.


If you want tto learn more about the entity, then get the entity list. You get the entity list by using the ENTGET fucntion.


This is how the entity list may look:


((-1 . <Entity name: 3774828>) (0 . "LINE") (5 . "1C4") (67 . 0) (8 . "0") (62 . 256) (6 . "ByLayer") (370 . -1) (347 . <Entity name: 0>) (284 . 0) (48 . 1.00000) (60 . 0) (39 . 0.000000) (10 -25.1534 -3.89644 0.000000) (11 44.0428 28.5361 0.000000) (210 0.000000 0.000000 1.00000))


The entity list consists of part list. In each part list there is an index number. The index number tells what information there is.


This is the meaning of some of the index numbers:


Index
number
Description


-1
Entity name
0
Entity type
8
Layer
10
Start point
11
End point


You have access to the information with the entity functions and the selection set functions. You can delete entities with AutoLISP.


We were talking about AutoCAD. But IntelliCAD has got the same structure.


















Friday, September 19, 2014

List Functions


In most programming languages they work with arrays. In AutoLISP there are no arrays. But you have lists in AutoLISP.


In fact. Lists can perform the same function as arrays. To learn more about it, take a look at my blog. I have written about it.


But let's talk about lists. There are lists functions. There are 18 list functions. Here is a list of them.


- List
- Append
- Cons
- Atom
- Listp
- Length
- Car
- Cdr
- Caar, Cadr, Cadar, Etc.
- Last
- Member
- Nth
- Reverse
- Assoc
- Subst
- Foreach
- Apply
- Mapcar


LIST


(list <expression>...)


This function makes a list of a loose element or loose elements.


Examples:


Function
Gives back




(list 'a 'b 'c)
(A B C)
(list 'a '(b c) “text”)
(A (B C) “text”)
(list 3.9 6.7)
(3.9 6.7)


APPEND


(append <expression>...)


This function creates a new list out of two or more lists.


Function
Gives back




(append '(a b) '(c d))
(A B C D)
(append '((a) (b)) '(c))
((A) (B) C)


CONS


(cons <new> <list>)


A new element is added to the list. The new element can be an atom or a list. It comes at the first place of the list. Examples are:


Function
Gives back




(cons 'a '(b c d))
(A B C D)
(cons '(a) '(b c d))
((A) B C D)


Instead of a new element and a list, this function can also be used with two atoms. Then you will get a dotted pair. Examples:


Function
Gives back




(cons 2 'a)
(2 . A)
(cons 8 “0”)
(8 . “0”)


ATOM


(atom <item>)


This function gives back nil if the item is a list. If not it gives back T or true.


Examples:


(setq a '(x y z))
(setq b 'a)


Function
Give back




(atom 'a)
T
(atom a)
nil
(atom 'b)
T
(atom b)
T
(atom '(a b c))
nil


LISTP


(listp <item>)


This function is the same as the prevision function. Except it gives back T if the item is a list and nil if it is not a list.


Function
Gives back




(listp '(a b c))
T
(listp 'a)
nil
(listp 3.434)
nil


LENGTH


(length <list>)


This function gives the number of element of a list. Or the length of a list.


Function
Gives back




(length '(a b c d))
4
(length '(a b (c d))
3
(length '())
0


CAR


(car <list>)


This function gives back the first element of a list. What is given back can be an atom or a list. If the list is empty, nil is given back.


Examples:


Function
Gives back




(car '(a b c))
3
(car '((a b) c)
2
(car '())
nil


CDR


(cdr <list)


This function gives back the list without the first element. The first element can be an atom or a list.


Examples:


Function
Gives back




(cdr '(a b c))
(B C)
(cdr '((a b) c)
(C)
(cdr '())
nil


CAAR, CADR, CADAR, etc.


These functions are a combination of the previous functions. You can combine the functions until four levels.


LAST


(last <list>)


The function gives back the last element of a list. Examples:


Function
Gives back




(last '(a b c d))
D
(last '(a b (c d))
(C D)


MEMBER


(member <expression> <list>)


This function checks if the expression is in the list. If so the list is given back starting with the expression.


Function
Gives back




(member 'c '(a b c d e))
(C D E)
(member 'z '(a b c d e))
nil


NTH


(nth <list>)


This function gives back the nth number minus 1 of the list. The elements of the list are numbered., The number of the first element is zero.


Function
Gives back




(nth 3 '(a b c d e))
D
(nth 0 '(a b c d e))
A
(nth 9 '(a b c d e))
nil


REVERSE


(reverse <list>)


This function turns the order of a list around. Example:


Function
Give back




(reverse '(a b c))
(C B A)


ASSOC


(assoc <item> <list)


This function gives back a part list of a list depending on whether the item has been found in the list.


Examples:


(setq ls '((name box) (width 100) (height 200))


Function
Gives back




(assoc 'name a)
(NAME BOX)
(assoc 'width a)
(WIDTH 100)
(assoc 'length a)
nil


SUBST


(subst <new item> <old item> <list>)


This function looks in a list for an old item and replaces it with the new item. If the anew item can be found.


If the old item is not found, then the original list is given back.


Examples:


(setq dm '(a b (c d) b))


Function
Gives back




(subst 'qq 'b dm)
(A QQ (C D) QQ)
(subst 'qq 'z dm)
(A B (C D) B)
(subst 'qq (c d) dm)
(A B QQ B)
(subst '(qq rr) 'c d) dm)
(A B (QQ RR) B)


FOREACH


(foreach <name> <list> <expression>)


This function goes through a list. Every item is given a name and the name is evaluated according to the expression.


The result of the last item and expression is what is given back by the fucntion.


Example:


Function
Gives back




(foreach nm '(1 2 3) (* nm 2))
6


In the example the following calculations have been made:


(* 1 2)
(* 2 2)
(* 2 3)


APPLY


(apply <function> <list>)


With this function elements of a list can be evaluated. Examples:


Function
Gives back




(apply '+ '(1 2 3))
6
(apply 'strcat '(“Auto” “LISP”)
AutoLISP


MAPCAR


(mapcar <function> <list1>...<listn>)


This function evaluates the function specified with all the lists as arguments. In the lists must be the number of needed arguments.


Example:


(setq a 10 b 20 c 30)
(mapcar '1+ (list a b c))


gives back:


(11 21 31)


That is:


(1+ a)
(1+ b)
(1+ c)


(mapcar '+ (10 20 30) (4 3 2))


gives back:


(14 23 32)


That is:


(+ 10 4)
(+ 20 3)
(+ 30 2)