@Anonymous ,
To help understand your function, let's first cover what a DXF code is:
- A DXF code is a number (an integer), and this number will ALWAYS be paired with another piece of information. Together these 2 items will create a Dotted Pair. Every entity in AutoCAD is composed of many dotted pairs. These dotted pairs, together, store all information necessary to identify how an entity is built / constructed.
Now, since we need to be able to build entities and likewise retrieve entity information, we need to categorically save or search for this information in some orderly fashion. The DXF codes maintain this order. This means that if know how to interpret what piece of information is attached with the DXF code in our Dotted Pair, then we can make use of it.
Let's look at a quick example:
If you look at THIS list of DXF codes, we can see that DXF group code 8 represents the layer name. Now that we know this information (and also remember that DXF code = ALWAYS part of a dotted pair), if we were to locate a dotted pair with a DXF code of 8, we will also know that the other piece of information in that dotted pair will be the layer name!
It would look like this:
(8 . "Defpoints")
(Now, remember, the second piece is merely the layer name and will not always be "Defpoints")
Awesome, now we know how to interpret our dotted pairs! So what about your function? Ok, so now we have to throw some more info into the mix.
Using this line of code, we can select an entity and return its list of entity information (in this case we select a LINE):
(entget (car (entsel "\nSelect an Entity: ")))
Example return:
((-1 . <Entity name: 1bbd1d0>) (0 . "LINE") (330 . <Entity name: 1bbd0c8>)
(5 . "6A") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine")
(10 1.0 2.0 0.0) (11 6.0 5.0 0.0) (210 0.0 0.0 1.0))
Nice, look at those Dotted Pairs! This is sometimes called an entity list. We can use our DXF code references to find out what all those numbers mean inside this entity list.
But how can we extract the layer name from this elist (entity list)? Well, we can use your function!
If we pass the layer DXF code (the number 8) and the elist to your function, it will use the ASSOC function to search the elist for a dotted pair containing your provided DXF code, then return the second piece of information from that dotted pair (using the CDR function).
It would look like this:
(dxf 8 ((-1 . <Entity name: 1bbd1d0>) (0 . "LINE") (330 . <Entity name: 1bbd0c8>)
(5 . "6A") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine")
(10 1.0 2.0 0.0) (11 6.0 5.0 0.0) (210 0.0 0.0 1.0)))
This would return:
"0"
Layer name is 0! (it looks like a lot, but this is merely your code = 8 & elist = [all the items associated with the entity])
HERE is a really great and thorough document for DXF codes (save it for later).
While your function is a simple one, it may help you to learn how to access entity information in a simplistic manner.
Hope this helps. Best,
~DD