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.




No comments:

Post a Comment