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.