Extended Entity Data - Part 1
- See also:
- Extended Entity Data - Part 2
What is Extended Entity Data?
For years AutoCAD has had the ability to store user information within a drawing by utilising attributes. But, attributes have got their limitations. They've got to be a block, or part of a block. They can be difficult to use. They can be exploded or modified by the user and they can only hold certain types of information.
Extended Entity Data though, allows you to attach up to 16K of information to each and every entity in the drawing. You can also keep it totally separate from other information and, because it uses a uniquely registered name, can be kept relatively safe from being overwritten. You can also store lot's of different types of information in Extented Entity Data.
Extended Entity Data is attached to an entity as an associated list with a code number of -3. The simplest form of an Xdata Associative list would look something like this :
((-3 ("AFRALISP" (1000 . "Kenny is great"))))
Firstly, let's look at some of the different types of xdata that you can attach to an entity :
Data Type | Code | Description |
---|---|---|
String | 1000 | A string of up to 255 characters. |
Application Name | 1001 | An Application Name. |
Layer Name | 1003 | The name of a Layer. |
DataBase Handle | 1005 | The handle of an entity. |
3D Point | 1010 | A 3D Coordinate value. |
Real | 1040 | A real value. |
Integer | 1070 | A 16 bit integer (signed or unsigned). |
Long | 1071 | A 32 bit signed (long) integer. |
Control String | 1002 | A control code to set off nested list. |
World Space Position | 1011 | A 3D coordinate point that is moved, scaled rotated, streched and mirrored along with the entity. |
World Space Displacement | 1012 | A 3D coordinate point that is scaled, rotated or mirrored along with the entity. It cannot be stretched. |
World Space Direction | 1013 | A 3D coordinate point that is rotated or mirrored along with the entity. It cannot be scaled, streched or moved. |
Distance | 1041 | A real value that is scaled along with the entity. Used for distance. |
Scale Factor | 1042 | A real value that is scaled along with the entity. Used as a scale factor. |
Another important thing to remember about Xdata is that you can have more than one of the same associative code.
Let's attach some xdata to an entity in a drawing. Draw a line then type this:
(regapp "AFRALISP")
AutoLisp should return :
"AFRALISP"
You have now registered your external entity data name. This name is a unique identifier to your own extended entity data. Next we need to get the entity data list of the entity that we want to add exdata to. Type this :
(setq oldlist (entget (car (entsel))))
AutoLisp should return something like this :
Select object: ((-1 . <Entity name: 2100888>) (0 . "LINE") (5 . "271") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbLine") (10 336.561 591.45 0.0) (11 672.362 497.304 0.0) (210 0.0 0.0 1.0))
Now, let's create the exdata that we want to add to the entity :
(setq thedata '((-3 ("AFRALISP" (1000 . "Kenny is handsome") (1000 . "And intelligent")))))
Append it to the entity data list :
(setq newlist (append oldlist thedata))
Now, update the entity :
(entmod newlist)
We have now attached the xdata to the entity. To retrieve it we would type this :
(setq elist (entget (car (entsel)) '("AFRALISP")))
This would return the modified entity list. It should look something like this :
Select object: ((-1 . <Entity name: 2100888>) (0 . "LINE") (5 . "271") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbLine") (10 336.561 591.45 0.0) (11 672.362 497.304 0.0) (210 0.0 0.0 1.0) (-3 ("AFRALISP" (1000 . "Kenny is handsome") (1000 . "And intelligent"))))
To retrieve the xdata we would type this :
(setq exlist (assoc -3 elist))
This gets the xdata list from the entity list.
(-3 ("AFRALISP" (1000 . "Kenny is handsome") (1000 . "And intelligent")))
To retrieve the xdata itself we would type this :
(setq thexdata (car (cdr exlist)))
Now, we should have this :
("AFRALISP" (1000 . "Kenny is handsome") (1000 . "And intelligent"))
We now have an ordinary list. Because we created the xdata list, and we know in what order we created it, it's very simple to retrieve each individual part :
(setq data1 (cdr (nth 1 thexdata))) (setq data2 (cdr (nth 2 thexdata)))
This should return :
"Kenny is handsome" "And intelligent"
This, of course, is a factual statement.
In Part 2 we will have a look at a practical example using Xdata. Come on, don't be scared…