jpsheader.jpg (29354 bytes)

Back to AutoLisp Advanced Tutorial HomePage

Back to AutoLisp Tutorial HomePage

Back to AutoLisp HomePage

Back to JefferyPSanders.com

 

 

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

 

A

U

T

O

L

I

S

P

 

A

D

V

A

N

C

E

D

 

T

U

T

O

R

I

A

L

 

 

The AutoLisp Advanced Tutorial


Entity DXF Group Code Descriptions For:

Arc 

Attribute

Circle

Ellipse

Image

Insert / Block

Line

LWPolyLine

MLine

MText

Point/Node

PolyLine

Solid 

Text

Trace

XLine

Note:  A good working example of all of these DXF group codes can be found in the CAD2File.lsp program on the AutoLisp home page.   All code is remarked to make it easier to follow along. 


Arc 

Typical DXF Group Codes for an ARC Entity:

To list an arc entity in AutoCAD you type LIST<enter> and select the arc.  To do this in AutoLisp you would:

(setq en(car (entsel "\n Select an Arc: ")))

(setq enlist(entget en))

Would return:

((-1 . <Entity name: 2b80648>) (0 . "ARC") (5 . "89")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 ."AcDbCircle")
 (10 1.5 0.5 0.0) (40 . 1.58114) (210 0.0 0.0 1.0) (100 . "AcDbArc")
 (50 .5.96143) (51 . 3.46334))
What does all of this garbage mean?

Let's take it apart and put it in order:

(

  (-1 . <Entity name:2b80648>) -1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "ARC")                                    0    -  Entity Type

  (5 . "89")                                       5   -  Handle Name  (If handles are turned on)

  (8 . "STR")                                     8   -  Layer Name

  (10 1.5 0.5 0.0)                       10   -  Center Point

  (40 . 1.58114)                            40   -  Radius

  (50 .5.96143)                               50   -  Start Angle Expressed in Radians

  (51 . 3.46334)                            51   -  End Angle Expressed in Radians

  (67 . 0)                                          67 -    Don't worry about this

  (100 . "AcDbEntity")             100 -   Don't worry about this

  (100 ."AcDbCircle")                100 -  Don't worry about this

  (100 . "AcDbArc")                     100 -   Don't worry about this Sub Class Marker

  (210 0.0 0.0 1.0)                     210 -   Don't worry about this Extrusion Factor

)

Let's play with it:

(cdr(assoc 10 enlist)) would return (1.5 0.5 0.0)

Remember, CDR returns everything after the first item in a list.

To get the center point of the arc :

   (cdr (assoc 10 enlist))

To get the radius of the arc :

     (cdr(assoc 40 enlist))

To get the layer name of the arc  :

     (cdr(assoc 8 enlist))

To get the start angle of the arc  :

     (cdr(assoc 50 enlist)) 

To get the end angle of the arc  :

     (cdr(assoc 51 enlist))

To see if the entity is indeed an ARC entity  :

     (if (= "ARC" (cdr(assoc 0 enlist)))


Attribute

This may be a little lengthy.  Better grab a cup of joe before getting started. 

  First off, an attribute is located inside a block entity.   This means the entities contained inside a block are called   sub-entities.  All entities (Lines, text, attributes, etc.) inside the block are sub-entities.  You have to (I'll retract this later) start with the block entity and step your way into it to find the sub-entities.  Kind of like this :

(block entity  name   (sub-entity name 1)   (sub-entity name 2)   (sub-entity name 3)   SEQEND )

  You start with the Block's entity name and step through until you find SEQEND using the ENTNEXT function.  I'll get back to this a little later on.

  You have a couple of choices on how to get to the attribute entity inside the block.   Now, after I've gone on the record saying "You have to start at the top and step your way down through the sub-entities using ENTNEXT", I'm going to prove myself wrong. 

  The easiest method is using NENTSEL.  I have not discussed the NENTSEL function until now.  NENTSEL will return the DXF group code list for a sub-entity inside a block or 3d Polyline. We will stick to blocks for this discussion.    You have to actually pick the attribute sub-entity and not any sub-entity contained inside the block.  You can then modify the DXF group codes and update the attribute.  This is fine for single selection and single manipulation of one attribute inside the block.  I'll give a quick demonstration of the NENTSEL function.

(setq ent(nentsel "\n Select a sub-entity: "))

  NENTSEL returns the exact same thing as ENTSEL if the entity selected is not a complex entity like a Block or 3d Polyline.  If you selected acomplex entity such as an attribute inside a block, NENTSEL would return something like this:

(<Entity name: 400a14a8> (5193.24 4935.03 0.0)( (20.0 0.0 0.0)  (0.0 20.0 0.0) (0.0 0.0 20.0) (5237.78 4923.46 0.0)) (<Entity name: 40222278>))

Let's break it down:

(<Entity name: 400a14a8>          - The actual entity name of the entity selected.

  (5193.24 4935.03 0.0)           - The point selected.

  (                               - Start of a four item list

    (20.0 0.0 0.0)                - We will ignore the Model to World Transformation Matrix

    (0.0 20.0 0.0)                - We will ignore the Model to World Transformation Matrix

    (0.0 0.0 20.0)                - We will ignore the Model to World Transformation Matrix

    (5237.78 4923.46 0.0)         - We will ignore the Model to World Transformation Matrix

  )                               - End of a four item list

  (<Entity name: 40222278>)       - The entity name of the block that contains the selected entity

)

To get the DXF Group codes of the selected attribute using NENTSEL :

(if (setq ent(nentsel "\n Select Attribute: "))  ;- Select the attribute

  (progn

    (setq en(car ent))                            ;- Get the entity name

    (setq enlist(entget en))                      ;- Get the DXF Group codes

  )

  (princ "\n Nothing Selected!")                    ;- Print message on failure  

)

  That's enough on NENTSEL.  Let's get back to work finding attribute information. 


First thing we need to do is let the user select a block :

(setq ent(entsel "\n Select a block: "))

Then let's get the entity name and dxf group codes of the block:

(setq en(car ent))

(setq enlist(entget en))

Command: !enlist<enter>  returns:

((-1 . <Entity name: 40222278>) (0 . "INSERT") (330 . <Entity
name: 40073cf8>) (5 . "85F") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"DELAMINATION") (100 . "AcDbBlockReference") (66 . 1) (2 . "Atl17") (10 5237.78
4923.46 0.0) (41 . 20.0) (42 . 20.0) (43 . 20.0) (50 . 0.0) (70 . 0) (71 . 0)
(44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))

Let's take it apart, put it in order, and get rid of the codes that are not needed:

Note: If you want to see the other group codes please see the Insert / Block entity on this page.

(

  (-1 . <Entity name: 40222278>)   -1 - Entity name

  (0 . "INSERT")                     0 - Entity type

  (2 . "Atl17")                      2 - Name of the block

  (10 5237.78 4923.46 0.0)           10 - Insertion Point

  (41 . 20.0)                        41 - X scale factor

  (42 . 20.0)                        42 - Y scale factor

  (43 . 20.0)                        43 - Z scale factor

  (50 . 0.0)                         50 - Rotation angle

  (66 . 1)                           66 - Attributes follow flag

)

  Notice the red code.  Code number 66.  This is the important one for finding attributes.  If this code has a value of zero, there are no attributes in the block.  If it has a value of 1, the block contains attributes.  You find the attributes by stepping through the block using ENTNEXT until you reach the SEQEND entity.

  So,  how do we do that?  Like this:

To get the attribute's DXF group codes:

(if (setq ent(entsel "\n Select a Block: ")) ;- Let the user select a block

(progn                                                   

  (setq en(car ent))                                                        ;- Get the entity name of the block

  (setq enlist(entget en))                                          ;- Get the DXF group codes

  (setq blkType(cdr(assoc 0 enlist)))                 ;- Save the type of entity

  (if (= blkType "INSERT")                                          ;- If the entity type is an Insert entity

   (progn

    (if(= (cdr(assoc 66 enlist)) 1)    ;- See if the attribute flag equals one (if so, attributes follow)

    (progn

      (setq en2(entnext en))                                    ;- Get the next sub-entity

      (setq enlist2(entget en2))                           ;- Get the DXF group codes

      (while (/= (cdr(assoc 0 enlist2)) "SEQEND")  ;- Start the while loop and keep                                                                                                                   ;-  looping until SEQEND is found.

        (princ "\n ")                                                 ;-Print a new line

        (princ enlist2)                                               ;- Print the attribute DXF group codes

        (setq en2(entnext en2))                             ;- Get the next sub-entity

        (setq enlist2(entget en2))                      ;- Get the DXF group codes

      )

     )

    )  ;- Close the if group code 66 = 1 statement

   )

  )   ;- Close the if block type = "ATTRIB" statement

)

)   ;- Close the if an Entity is selected statement

 

Finally we get to see the Attribute DXF group codes which should be printed out on your command line or text screen.  They should look something like this:

((-1 . <Entity name: 40222290>) (0 . "ATTRIB") (330 . <Entity name: 40222278>)
(5 . "862") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "TITLETXT_S")
(100 . "AcDbText") (10 5191.7 4940.62 0.0) (40 . 1.6) (1 . "CTSE890") (50 .
0.0) (41 . 1.0) (51 . 0.0) (7 . "arial80") (71 . 0) (72 . 0) (11 0.0 0.0 0.0)
(210 0.0 0.0 1.0) (100 . "AcDbAttribute") (2 . "PROJ") (70 . 0) (73 . 0) (74 .
0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 40222290>)      -1 - Entity name

  (0 . "ATTRIB")                       0 - Entity Type 

  (1 . "CTSE890")                      1 - Attribute Value

  (2 . "PROJ")                         2 - Attribute Tag

  (5 . "862")                          5 - Handle

  (7 . "arial80")                      7 - Text Style

  (8 . "TITLETXT_S")                   8 - Layer name

  (10 5191.7 4940.62 0.0)             10 - Insertion Point

  (11 0.0 0.0 0.0)                    11 - Text alignment point (optional)

  (40 . 1.6)                          40 - Text Height

  (41 . 1.0)                          41 - X scale factor  (also used for fit text)

  (50 . 0.0)                          50 - Text Rotation

  (51 . 0.0)                          51 - Text Oblique Angle

  (67 . 0)                            67 -  Absent or zero = model space / 1 = paper space

  (70 . 0)                            70 - Attribute flag
                                         0 =  No flags
                                         1 = Invisible
                                         2 = Constant
                                         4 = Verification is Required
                                         8 = Preset (no prompt)

  (71 . 0)                            71 - Text Generation Flag (See text entity)

  (72 . 0)                            72 - Horiz. Text Justification (See text entity)

  (73 . 0)                            73 - (See text entity)

  (74 . 0)                            74 -  Vertical Text Justication (See text entity)

  (100 . "AcDbEntity")               100 - Ignore

  (100 . "AcDbText")                 100 - Ignore

  (100 . "AcDbAttribute")            100 - Ignore

  (210 0.0 0.0 1.0)                  210 - Extrusion direction (ignore)

  (330 . <Entity name: 40222278>)    330 - Ignore

  (410 . "Model")                    410 - Layout Tab Name

)

Let's play with it:

To get the value of the attribute using the program from above:

(cdr(assoc 1 enlist2))

To get the attribute Tag:

(cdr(assoc 2 enlist2))

To change the value of the attribute:

Syntax: (subst new_item  old_item  entity_list)

(setq newVal (getstring "\n New Attribute value: "))

(setq enlist2 (subst (cons 1 newVal) (assoc 1 enlist2) enlist2))

(entmod enlist2)

(entupd en2)

 If you have any questions <Send Email>


Circle 

Typical DXF Group Codes for a Circle Entity:

To list a circle in AutoCAD you type LIST<enter> and select the circle.  To do this in AutoLisp you would:

(setq en(car(entsel "\n Select a Circle: ")))

(setq enlist(entget en))

Would return:

((-1 . <Entity name: 37b0650>) (0 . "CIRCLE") (5 . "8A")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbCircle")
(10 17.4375 9.6875 0.0) (40 . 1.5) (210 0.0 0.0 1.0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 37b0650>)   -1 - AutoCad Entity Name (AutoCAD does this Automatically)

  (0 . "CIRCLE")                   0 - Entity Type

  (5 . "8A")                       5 - Handle Name (If handles are turned on)

  (8 . "STR")                      8 - Layer Name

  (10 17.4375 9.6875 0.0)          10 - Center point of circle

  (40 . 1.5)                       40 - Radius of circle

  (67 . 0)                         Don't worry about this

  (100 . "AcDbCircle")             Don't worry about this

  (100 . "AcDbEntity")             Don't worry about this

  (210 0.0 0.0 1.0)                Don't worry about this

)

Let's play with it:

(cdr(assoc 10 enlist)) would return (17.4375 9.6875 0.0)

Remember, CDR returns everything after the first item in a list.

To get the radius of the circle :

   (cdr (assoc 40 enlist))

To get the center of the circle :

     (cdr(assoc 10 enlist))

To get the layer name of the circle  :

     (cdr(assoc 8 enlist))

To see if the entity is indeed a CIRCLE entity  :

     (if (= "CIRCLE" (cdr(assoc 0 enlist)))


Ellipse

Typical DXF Group Codes for an ELLIPSE Entity:

To list an ellipse entity in AutoCAD you type LIST<enter> and select the ellipse. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select an Ellipse :")))
(setq enlist(entget en))


Would return:

( (-1 . <Entity name: 1cb0670>) (0 . "ELLIPSE") (5 . "86")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbEllipse")
(10 3.0 3.0 0.0) (11 21.2132 -21.2132 0.0) (210 0.0 0.0 1.0)
(40 . 0.0471405) (41 . 0.0) (42 . 6.28319) )


Let's take it apart and put it in order:

(

  (-1 . <Entity name:1cb0670>)
-1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "ELLIPSE")                                      0 - Entity Type

  (5 . "86")                                                   5 - Handle Name (If handles are turned on)

  (8 . "STR")                                                8 - Layer Name

  (10 3.0 3.0 0.0)                                  10 - Center Point

  (11 21.2132 -21.2132 0.0)            11 - end Point of Major axis (relative to center)

  (40 . 0.0471405)                                   40 - Ratio of Minor axis to Major axis

  (41 . 0.0)                                                  41 - Start Parameter (Equals 0.0 for closed ellipse)

  (42 . 6.28319)                                        42 - End Parameter (Equals 2 * pi for closed ellipse)

  (67 . 0)                                                       67 - Absent or zero indicates the entity is in
                                                                                      model space. If set to 1, paper space.

  (100 . "AcDbEntity")                        100 - Don't worry about this

  (100 ."AcDbEllipse")                        100 - Don't worry about this

  (210 0.0 0.0 1.0)                                210 - Don't worry about this Extrusion Factor

)


Let's play with it:

(cdr(assoc 10 enlist)) would return (3.0 3.0 0.0)

Remember, CDR returns everything after the first item in a list.

To get the center point of the ellipse :

(cdr (assoc 10 enlist))

To get the length of the major axis :

;;;--- Save the center point of the ellipse
(setq centerPt(cdr(assoc 10 enlist)))

;;;--- Save the endPoint of the major axis relative to center pt
(setq endPt(cdr(assoc 11 enlist)))

;;;--- Create a new point on the end of the major axis

;;;    by subtracting code 10 point from code 11 point
(setq newPt
  (list
    (- (car centerPt)(car endPt))
    (- (cadr centerPt)(cadr endPt))
  )
)

;;;--- Finally, find the major axis length
(setq majorAxisLength(* 2.0 (distance centerPt newPt)))

To get the length of the minor axis :

(* majorAxisLength (cdr(assoc 40 enlist)))

             Note: See example above for majorAxisLength

To see if the entity is indeed an Ellipse entity :

(if (= "ELLIPSE" (cdr(assoc 0 enlist)))


Image

To list an image entity in AutoCAD you type LIST<enter> and select the image. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select an Image :")))
(setq enlist(entget en))


Would return some garbage like this:

((-1 . <Entity name: 40073da8>) (0 . "IMAGE") (330 . <Entity
name: 40073cf8>) (5 . "4D") (100 . "AcDbEntity") (410 . "Model") (8 . "0") (100 . "AcDbRasterImage") (90 . 0) (10 9.00868 6.59115 0.0) (11 0.0012987
0.0 0.0) (12 7.95199e-020 0.0012987 0.0) (13 770.0 559.0 0.0) (340 . <Entity
name: 40073d98>) (70 . 7) (280 . 0) (281 . 50) (282 . 50) (283 . 0) (360 .
<Entity name: 40073da0>) (71 . 1) (91 . 2) (14 -0.5 -0.5 0.0) (14 769.5 558.5
0.0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 40073da8>)   -1 Entity Name (AutoCAD Automatically takes care of this)

  (0 . "IMAGE")                     0 - Entity Type

  (5 . "4D")                        5 - Handle Name (If handles are turned on)

  (8 . "0")                         8 - Layer Name

  (10 9.00868 6.59115 0.0)          10 - Insertion Point

  (11 0.0012987 0.0 0.0)            11 - U-vector of a single pixel (points along the visual
                                        bottom of the image, starting at the insertion
                                        point) (in OCS)

  (12 7.95199e-020 0.0012987 0.0)   12 - V-vector of a single pixel (points along the visual left
                                        of the image, starting at the insertion point) (in OCS)

  (13 770.0 559.0 0.0)              13 - Image size in pixels

  (14 -0.5 -0.5 0.0)                14 - Clip boundary vertex (in OCS)
                                        1 .  For rectangular clip boundary type, two opposite
                                        corners must be specified. Default is (-0.5,-0.5),
                                        (size.x-0.5, size.y-0.5).
                                        2 .   For polygonal clip boundary type, three or more
                                        vertices must be specified. Polygonal vertices
                                        must be listed sequentially.

  (14 769.5 558.5 0.0)               14 - Other corner for rectangular.  See (1) above.

  (70 . 7)                          70 - Image display properties (Can be added together)
                                                                                            1.   Show Image
                                                                                            2.   Show image when not aligned with screen.
                                                                                            4.   Use clipping boundary
                                                                                            8.   Transparency is on.

                                                                                        With a value of  7 it is using 1, 2, & 4

  (71 . 1)                           71 - Clipping boundary type. 1= Rectangular 2=Polygonal

  (90 . 0)                           90 - Class Version

  (91 . 2)                          91 - Number of clip boundary vertices that follow.

  (330 . <Entity name: 40073cf8>)  330 - Ignore

  (100 . "AcDbEntity")             100 - Ignore

  (100 . "AcDbRasterImage")        100 - Ignore

  (280 . 0)                        280 - Clipping state  0=Off 1=On

  (281 . 50)                       281 - Brightness Value 0 to 100  (Default = 50)

  (282 . 50)                       282 - Contract Value 0 to 100  (Default = 50)

  (283 . 0)                        283 - Fade Value 0 to 100  (Default = 0)

  (340 . <Entity name: 40073d98>)  340 - Ignore Hard reference to imagedef object

  (360 . <Entity name: 40073da0>)  360 - Ignore Hard reference to imagedef_reactor object

  (410 . "Model")                  410 - Layout tab name

)

Let's play with it:

(cdr(assoc 10 enlist)) would return (9.00868 6.59115 0.0)

Remember, CDR returns everything after the first item in a list.

To get the insertion point of the image :

(cdr (assoc 10 enlist))

To get the image size in pixels :

(setq x(car(cdr(assoc 13 enlist))))

(setq y(cadr(cdr(assoc 13 enlist))))

To get the layer name of the image :

(cdr(assoc 8 enlist))

To get the layout Tab name :

(cdr(assoc 410 enlist))


Insert / Block

Typical DXF Group Codes for an INSERT Entity:

To list an insert entity in AutoCAD you type LIST<enter> and select the block. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a block :")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 1c90970>) (0 . "INSERT") (5 . "EB6")
(100 . "AcDbEntity") (67 . 0) (8 . "TX") (100 . "AcDbBlockReference")
(2 . "HR") (10 1.5 0.5 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0)(70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0))


Let's take it apart and put it in order:

(

    (-1 . <Entity name:1c90970>) -1 - Entity Name (AutoCAD Automatically takes care of this)

    (0 . "INSERT")                                         0 - Entity Type

    (1 . "PATH")                                        1 - Xref path name

              Note: GROUP CODE 1 is optional.
                        It is present only if the block is an xref.


    (2 . "HR")                                                2 - Name of Block

    (5 . "EB6")                                             5 - Handle Name (If handles are turned on)

    (8 . "TX")                                                8 - Layer Name

    (10 1.5 0.5 0.0)                               10 - Insertion Point

    (41 . 1.0)                                              41 - X Scale Factor. Optional, 1 = default

    (42 . 1.0)                                              42 - Y Scale Factor. Optional, 1 = default

    (43 . 1.0)                                              43 - Z Scale Factor. Optional, 1 = default

   (44 . 0.0)                                             44 - Don't worry about this. Optional.

     (45 . 0.0)                                             45 - Don't worry about this. Optional.

     (50 .5.96143)                                     50 - Rotation Angle Expressed in Radians

     (66 . 0)                                                  66 - Flag meaning attributes follow. Optional.

                 0 = Default
                 1 = Attributes-follow flag
                 A series of attribute entities is expected to follow the insert,
                 terminated by a SEQEND entity.



  (67 . 0)                                                  67 - Absent or zero indicates the entity is in
                                                                                 model space. If set to 1, paper space.

  (70 . 0)                                                 70 - Flag See the following:

              Block flags:
              0 = Normal
              1 = This is an anonymous block generated by hatching,
                    associative dimensioning, other internal operations,
                    or an application
              2 = This block has attribute definitions
              4 = This block is an external reference (xref)
              8 = This block is an xref overlay
            16 = This block is externally dependent
            32 = This is a resolved external reference,
                     or dependent of an external reference
                    (ignored on input)
            64 = This definition is a referenced external reference
                     (ignored on input)

                 Note: Block flags may be combined. For instance,
                           a 70 DXF group code of 6 would mean the block
                           has attributes (code 2) and is an external
                           reference (code 4). Because 2 + 4 = 6


  (71 . 0)                                                    71 - Don't worry about this.

  (100 . "AcDbEntity")                    100 - Don't worry about this

  (100 ."AcDbBlockReference")  100 - Don't worry about this

  (210 0.0 0.0 1.0)                            210 - Don't worry about this Extrusion Direction

)


Let's play with it:

(cdr(assoc 10 enlist)) would return (1.5 0.5 0.0)

Remember, CDR returns everything after the first item in a list.

To get the insertion point of the block :

(cdr (assoc 10 enlist))

To get the name of the block :

(cdr(assoc 2 enlist))

To get the layer name of the block :

(cdr(assoc 8 enlist))

To get the group 70 block flag :

(cdr(assoc 70 enlist))

To get the X scale factor of the block :

(cdr(assoc 41 enlist))

To see if the entity is indeed a BLOCK entity :

(if (= "INSERT" (cdr(assoc 0 enlist)))


Line 

Typical DXF Group Codes for a LINE Entity:

To list a line in AutoCAD you type LIST<enter> and select the line.  To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a Line: ")))

(setq enlist(entget en))

Would return:

((-1 . Entity name: 37b0648) (0 ."LINE") (5 . "89")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbLine")
(10 9.0 7.9375 0.0) (11 11.1213 10.0588 0.0) (210 0.0 0.0 1.0))

Let's take it apart and put it in order:

(

  (-1 . Entity name: 37b0648)     -1 - AutoCad Entity Name (AutoCAD does this Automatically)

  (0 ."LINE")                        0 - Entity Type

  (5 . "89")                       69 - Handle name (if handles are turned on)

  (8 . "STR")                             8 - Name of Layer

  (10 9.0 7.9375 0.0)               10 - Start Point of Line

  (11 11.1213 10.0588 0.0)          11 - End Point of Line    

  (67 . 0)                         Don't worry about this

  (100 . "AcDbLine")               Don't worry about this SubClass Marker.

  (100 . "AcDbEntity")             Don't worry about this

  (210 0.0 0.0 1.0)                Don't worry about this.  This is default unless extruded.

)

I'll bet AutoCad doesn't look so mysterious anymore.  Does it?

Let's play with it:

(cdr(assoc 10 enlist)) would return (9.0 7.9375 0.0)

Remember, CDR returns everything after the first item in a list.

To get the length of the line we need the distance from the start point to the end point :

   (distance (cdr (assoc 10 enlist)) (cdr(assoc 11 enlist)) )

To get the angle of the line we need two points.  The start point and the end point :

     (angle (cdr(assoc 10 enlist))   (cdr(assoc 11 enlist)) )

To get the layer name of the line  :

     (cdr(assoc 8 enlist))

To see if the entity is indeed a LINE entity  :

     (if (= "LINE" (cdr(assoc 0 enlist)))


LWPolyLine

Typical DXF Group Codes for an LWPOLYLINE Entity:

To list an polyline entity in AutoCAD you type LIST<enter> and select the polyline. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a Polyline :")))

(setq enlist(entget en))

Would return:

((-1 . <Entity name: 1cb0658>) (0 . "LWPOLYLINE") (5 . "83")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbPolyline")(90 . 5) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 1.0 1.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 2.0 1.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 2.0 2.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 3.0 3.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 1.0 4.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))


Let's take it apart and put it in order:

(

  (-1 . <Entity name:1cb0658>)
-1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "LWPOLYLINE")                             0 - Entity Type

  (5 . "83")                                                 5 - Handle Name (If handles are turned on)

  (8 . "STR")                                               8 - Layer Name

  (38 . 0.0)                                                38 - Elevation (optional) Default = 0.0

  (39 . 0.0)                                                39 - Thickness (optional) Default = 0.0


     NOTE:
     The next series of codes are Vertex points (group 10 codes) followed by group 40 codes.
     These codes always appear in the list by order in which they were created.


    10 - Vertex 2D point
    40 - Starting Width of the polyline. This is optional. Default = 0.
           Code 40 is not used if group code 43 is set.
    41 - Ending Width of the polyline. This is optional. Default = 0.
           Code 41 is not used if group code 43 is set.
    42 - Bulge factor. Used to create arcs in the polyline.
    43 - Constant Width. Optional. Default = 0.
           Code 43 is not used if codes 40 and 41 are set.



  (10 1.0 1.0)                                           10 - First Vertex (Start Point)
  (40 . 0.0)                                                40 - First Vertex Starting Width
  (41 . 0.0)                                                41 - First Vertex Ending Width
  (42 . 0.0)                                                42 - First Vertex Bulge Factor

  (10 2.0 1.0)                                          10 - Second Vertex Point
  (40 . 0.0)                                               40 - Second Vertex Starting Width
  (41 . 0.0)                                               41 - Second Vertex Ending Width
  (42 . 0.0)                                               42 - Second Vertex Bulge Factor

  (10 2.0 2.0)                                         10 - Next Vertex Point
  (40 . 0.0)                                              40 - Next Vertex Starting Width
  (41 . 0.0)                                              41 - Next Vertex Ending Width
  (42 . 0.0)                                              42 - Next Vertex Bulge Factor

  (10 3.0 3.0)                                         10 - Next Vertex Point
  (40 . 0.0)                                              40 - Next Vertex Starting Width
  (41 . 0.0)                                              41 - Next Vertex Ending Width
  (42 . 0.0)                                              42 - Next Vertex Bulge Factor

  (10 1.0 4.0)                                         10 - Last Vertex Point
  (40 . 0.0)                                              40 - Last Vertex Starting Width
  (41 . 0.0)                                              41 - Last Vertex Ending Width
  (42 . 0.0)                                              42 - Last Vertex Bulge Factor

  (43 . 0.0)                                              43 - Constant Width

  (67 . 0)                                                   67 - Absent or zero indicates the entity is in
                                                                                   model space. If set to 1, paper space.

  (70 . 0)                                                   70 - Polyline Flag. See below.

                   FLAGS:
                   0 - Default
                   1 - Closed
               128 - PLINEGEN (Generation of LineType)


  (90 . 5)                                                   90 - Number of vertices

  (100 . "AcDbEntity")                   100 - Don't worry about this

  (100 ."AcDbPolyline")                 100 - Don't worry about this

  (210 0.0 0.0 1.0)                         210 - Don't worry about this Extrusion Factor

)


Let's play with it:

(cdr(assoc 10 enlist)) would return (1.5 0.5 0.0)

Remember, CDR returns everything after the first item in a list.

To get the start point of the LWPolyline :

(cdr (assoc 10 enlist))

  Unfortunately, that is as far down as you can dig into the list. To get all of the group 10 codes,
  you will have to manually search for them.

  Here's an example:

(setq myVertexList(list)) ;create an empty list to store the vertices in.

(foreach a enlist                                              ;;;--- step through each sub-list
  (if(= 10 (car a))                                         ;;;--- if the first item in the sub-list equals 10 then
    (setq myVertexList                                 ;;;--- reset myVertexList to
      (append myVertexList                       ;;;--- the old vertex list
        (list                                                       ;;;--- plus a list containing
          (cdr a)                                             ;;;--- the vertex point
        )                                                                 ;;;--- close the list statement
      )                                                                      ;;;--- close the append statement
    )                                                                           ;;;--- close the setq statement
  )                                                                                ;;;--- close the if statement
)                                                                                     ;;;--- close the foreach statement

This would return:

( (1.0 1.0) (2.0 1.0) (2.0 2.0) (3.0 3.0) (1.0 4.0) )

A list of every vertex! Cool.


To get the layer name of the LWPolyline :

(cdr(assoc 8 enlist))

To see if the entity is indeed a LWPolyline entity :

(if (= "LWPOLYLINE" (cdr(assoc 0 enlist)))
  (princ "\n It is a LWPolyLine")
  (princ "\n It is not a LWPolyLine")
)


MLine

Typical DXF Group Codes for a MLine Entity:

To list a MLine in AutoCAD you type LIST<enter> and select the MLine.  To do this in AutoLisp you would:

(setq en(car (entsel "\n Select an MLine: ")))

(setq enlist(entget en))

Would return something like this :

((-1 . <Entity name: 40222978>) (0 . "MLINE") (330 . <Entity
name: 40073cf8>) (5 . "92F") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (100 . "AcDbMline") (2 . "STANDARD") (340 . <Entity name: 40073cc0>) (40 .
1.0) (70 . 0) (71 . 3) (72 . 4) (73 . 2) (10 11.4446 15.392 0.0) (210 0.0 0.0
1.0) (11 11.4446 15.392 0.0) (12 1.0 0.0 0.0) (13 0.690073 0.72374 0.0) (74 .
2) (41 . 0.0) (41 . 0.0) (75 . 0) (74 . 2) (41 . -1.38171) (41 . 0.0) (75 . 0)
(11 30.3875 15.392 0.0) (12 0.0 1.0 0.0) (13 -0.707107 0.707107 0.0) (74 . 2)
(41 . 0.0) (41 . 0.0) (75 . 0) (74 . 2) (41 . -1.41421) (41 . 0.0) (75 . 0) (11
30.3875 31.4532 0.0) (12 -1.0 0.0 0.0) (13 -0.707107 -0.707107 0.0) (74 . 2)
(41 . 0.0) (41 . 0.0) (75 . 0) (74 . 2) (41 . -1.41421) (41 . 0.0) (75 . 0) (11
10.6793 31.4532 0.0) (12 0.0475993 -0.998867 0.0) (13 0.72374 -0.690073 0.0)
(74 . 2) (41 . 0.0) (41 . 0.0) (75 . 0) (74 . 2) (41 . -1.44912) (41 . 0.0) (75
. 0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 40222978>)        -1 - Entity Name

  (0 . "MLINE")                        0 - Entity Type

  (2 . "STANDARD")                                         2 - Style (Must exist in MLineStyle Dictionary)

  (5 . "92F")                                                    5 - Handle (If handles are turned on)

  (8 . "0")                                                        8 - Layer Name

  (40 . 1.0)                                                    40 - Scale Factor

  (67 . 0)                                                        67 - Absent or zero indicates the entity is in
                                                                                         model space. If set to 1, paper space.

  (70 . 0)                                                       70 - Justification: 0 = Top, 1 = Zero, 2 = Bottom

  (71 . 3)                                                          71 - Flags - 1=Unlocked 2=Closed
                                                                                         4=Suppress start caps 8=Suppress end caps.

  (72 . 4)                                                        72 - Number of vertices

  (73 . 2)                                                        73 - Number of elements in MLineStyle Definition

  (10 11.4446 15.392 0.0)                           10 - Start Point

    ------------------------------------- Start the Vertex Loop    -------------------------------------

    Note: Each vertex will have a code 11, 12, 13, 74, 41, and 75.   I'm going to include the first appearance of codes 12, 13, 74, and 75 and delete the rest for clarity.  I'll explain later.

  (11 11.4446 15.392 0.0)                           11 - First Vertex point of multiple entries

  (12 1.0 0.0 0.0)                                           12 - Direction Vector for next line from this point

  (13 0.690073 0.72374 0.0)                       13 - Direction Vector of miter at this vertex

  (74 . 2)                                                             74 - Number of group 41's to follow (I'll explain later)

  (41 . 0.0)                                                         41 - First code 41

  (41 . 0.0)                                                         41 - Second code 41

  (75 . 0)                                                              75 - Number of group 42's to follow (fill parameters)

  (11 30.3875 15.392 0.0)                            11 - Second vertex point

  (12 0.0 1.0 0.0)                                            12 - Second Direction vector for next line

  (13 -0.707107 0.707107 0.0)                   13 - Second Direction for miter

  (11 30.3875 31.4532 0.0)                          11 - Third vertex point

  (12 -1.0 0.0 0.0)                                          12 - Third Direction vector for next line

  (13 -0.707107 -0.707107 0.0)                 13 - Third Direction for miter

  (11 10.6793 31.4532 0.0)                          11 - Fourth vertex point

  (12 0.0475993 -0.998867 0.0)                 12 - Fourth Direction vector for next line

  (13 0.72374 -0.690073 0.0)                     13 - Fourth Direction for miter

  (100 . "AcDbEntity")                                 100 - Ignore

  (100 . "AcDbMline")                                   100 - Ignore this subclass marker

  (210 0.0 0.0 1.0)                                        210 - Ignore extrusion direction

  (330 . <Entity name: 40073cf8>)         330 - Ignore

  (340 . <Entity name: 40073cc0>)       340 - Ignore (needed to modify MLineStyle.  See note below.

  (410 . "Model")                                           410 - Layout Tab Name

)

Notes: From the book...

The group code 41 may contain zero or more items. The first group code 41 value is the distance from the segment vertex along the miter vector to the point where the line element's path intersects the miter vector. The next group code 41 value is the distance along the line element's path from the point defined by the first group 41 to the actual start of the line element. The next is the distance from the start of the line element to the first break (or cut) in the line element. The successive group code 41 values continue to list the start and stop points of the line element in this segment of the mline. Linetypes do not affect group 41 lists.

The 2 group codes in mline entities and mlinestyle objects are redundant fields. These groups should not be modified under any circumstances, although it is safe to read them and use their values. The correct fields to modify are as follows:

Mline - The 340 group in the same object, which indicates the proper MLINESTYLE object.

Mlinestyle -The 3 group value in the MLINESTYLE dictionary which precedes the 350 group that has the handle or entity name of the current mlinestyle.

  Here's an example of how to get all of the vertices in a list:


(setq en(car(entsel "\n Select a MLine: ")))  ;;;--- Get the entity name

(setq enlist(entget en))                       ;;;--- Get the dxf group codes

(setq myVertexList(list))                           ;;;--- create an empty list to store the vertices in.

(setq v1(cdr(assoc 10 enlist)))                   ;;;--- Get the starting point of the mline

(setq myVertexList(append myVertexList (list v1)))   ;;;--- Add the point to the list

(foreach a enlist                                              ;;;--- step through each sub-list
  (if(= 11 (car a))                                         ;;;--- if the first item in the sub-list equals 11 then
    (setq myVertexList                                 ;;;--- reset myVertexList to
      (append myVertexList                       ;;;--- the old vertex list
        (list                                                       ;;;--- plus a list containing
          (cdr a)                                             ;;;--- the vertex point
        )                                                                 ;;;--- close the list statement
      )                                                                      ;;;--- close the append statement
    )                                                                           ;;;--- close the setq statement
  )                                                                                ;;;--- close the if statement
)                                                                                     ;;;--- close the foreach statement

This would return:

( (11.4446 15.392 0.0) (11.4446 15.392 0.0)(30.3875 15.392 0.0)(30.3875 31.4532 0.0)(10.6793 31.4532 0.0) )

A list of every vertex!

Extra.......Let's redraw the MLine with Lines:

(command "line" (car myVertexList))    ;;;--- Start the line command with the first vertex

(foreach a (cdr myVertexList)       ;;;--- Cycle through the rest of the vertex list

  (command a)                        ;;;--- Send the vertex to the line command

)

(command)                            ;;;--- End the line command


MText

Typical DXF Group Codes for an MText Entity:

To list MText in AutoCAD you type LIST<enter> and select the MText. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select MText: ")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 40222a10>) (0 . "MTEXT") (330 . <Entity name: 40073cf8>) (5 . "942") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbMText") (10 37.2758 63.7667 0.0) (40 . 0.2) (41 . 54.9151) (71
. 1) (72 . 5) (1 . "This is an Mtext string. ") (7 . "Standard") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 4.2) (43 . 0.266667) (50 . 0.0) (73 . 1) (44 . 1.0))

Let's take it apart and put it in order:

 

(

  (-1 . <Entity name: 40222a10>)         -1  -  Entity Name

  (0 . "MTEXT")                                                 0   -  Entity Type

  (1 . "This is an Mtext string. ")    1  -  Text Value (See Note 1 and 2 Below!!!)

  (5 . "942")                             5  -  Handle (If handles are turned on)

  (7 . "Standard")                        7  -  Text Style

  (8 . "0")                                       8   -  Layer Name

  (10 37.2758 63.7667 0.0)            10  -   Insertion Point

  (11 1.0 0.0 0.0)                      11  -  X Axis Direction Vector

  (40 . 0.2)                                    40   -  Initial Text Height

  (41 . 54.9151)                           41  -  Reference Rectangle Width

  (42 . 4.2)                                    42   -  Horizontal width of the characters (Ignored)

  (43 . 0.266667)                         43  -  Vertical Height of the MText entity (Ignored)

  (44 . 1.0)                                      44   -  Line Spacing factor (Optional)

  (50 . 0.0)                                     50   -  Rotation angle (Always in radians)

  (67 . 0)                                          67   -  Absent or zero indicates the entity is in
                                                                                                model space. If set to 1, paper space.

  (71 . 1)                                          71   -  Attachment point     1=Top          2=Top Center
                                                                                                 3= Top Right     4=Middle Left   5=Middle Center
                                                                                                 6=Middle Right  7=Bottom Left  8= Bottom Center
                                                                                                 9=Bottom Right

  (72 . 5)                                          72   -  Drawing Direction   1 = Left to Right
                                                                                                                               3 = Top to Bottom 
                                                                                                                               5 = Use Text Style Default

  (73 . 1)                                          73   -  Line Spacing Style
                                                                                                   1 = At Least (Taller characters will override)
                                                                                                   2 = Exact (Taller characters will not override)

  (100 . "AcDbEntity")                100  -  Ignore

  (100 . "AcDbMText")                 100  -  Ignore

  (210 0.0 0.0 1.0)                   210  -  Extrusion direction (Ignore)

  (330 . <Entity name: 40073cf8>)       330  -  Ignore

  (410 . "Model")                        410  -  Tab Layout Name

)

NOTE 1 :   Formatting!

    MText can contain formatting characters.  For instance, if I change the MText entity we used in the example above:

  (1 . "This is an Mtext string. ")

     to use the Arial font, underlined, and bold,  the MText value would look something like this:

  (1 . "{\\fArial|b1|i0|c0|p34;\\LThis is an Mtext string. \\Ftxt.shx; }")

  Not very pretty is it? 

Mtext formatting codes:

Format code        Purpose                                                                
\0...\o            Turns overline on and off
\L...\l           Turns underline on and off
\~                        Inserts a nonbreaking space
\\                          Inserts a backslash
\{...\}               Inserts an opening and closing brace
\File name;    Changes to the specified font file
\Hvalue;            Changes to the text height specified in drawing units
\Hvaluex;          Changes the text height to a multiple of the current text height
\S...^...;       Stacks the subsequent text at the \, #, or ^ symbol
\Tvalue;            Adjusts the space between characters, from.75 to 4 times
\Qangle;            Changes obliquing angle
\Wvalue;            Changes width factor to produce wide text
\A                          Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top)

Note: Use curly braces ({ }) to apply a format change only to the text within the braces. You can nest braces up to eight levels deep.

NOTE 2 :  String Length!

    If the number of characters in an MText entity is less than 250, all characters will be in group code number 1.  If you exceed 249 characters, the characters are broken up in 250 character chunks and placed under group code number 3.  The remainder of the characters will be in group code 1.  For instance, if I change the MText entity we used in the example above:

  (1 . "This is an Mtext string. ")

     into a string that is 600 characters long,  the MText value would look something like this:

  (1 . "1234567899123456789012345678911234567892123456789312345678941234567895123456789
61234567897123456789812345678991234567890 ")

  Where's the rest of the string?    It is stored in the group 3 codes.  There are two if them that are 250 characters each.

(3 .
"1234567890123456789112345678921234567893123456789412345678951234567896123456789
71234567898123456789912345678901234567891123456789212345678931234567894123456789
51234567896123456789712345678981234567899123456789012345678911234567892123456789
31234567894")

(3 .
"1234567895123456789612345678971234567898123456789912345678901234567890123456789
11234567892123456789312345678941234567895123456789612345678971234567898123456789
91234567890123456789112345678921234567893123456789412345678951234567896123456789
71234567898")

To put the string back together, you would have to use the STRCAT function on the group 3 codes first:

 

(setq myStr "")

(setq en(car(entsel "\n Select Mtext: ")))

(setq enlist(entget en))

(foreach a enlist

  (if (= 3 (car a))

    (setq myStr (strcat myStr (cdr a)))

  )

)

Then you would have to tack the string stored in group code 1 to the end.  Like this:

(setq myStr(strcat myStr (cdr(assoc 1 enlist))))

  

Let's play with it:

(cdr(assoc 10 enlist)) would return (37.2758 63.7667 0.0)

Remember, CDR returns everything after the first item in a list.

To get the initial height of the MText :

   (cdr (assoc 40 enlist))

To get the insertion :

     (cdr(assoc 10 enlist))

To get the layer name of the MText  :

     (cdr(assoc 8 enlist))

To get the text value of the MText  :

     (cdr(assoc 1 enlist)) ;if it less than 250 characters long (See Note 1 Above)

To get the rotation angle of the MText  :

     (cdr(assoc 50 enlist))

To see if the entity is indeed a MText entity  :

     (if (= "MTEXT" (cdr(assoc 0 enlist)))


Point / Node

Typical DXF Group Codes for an Point or Node Entity:

To list a point entity in AutoCAD you type LIST<enter> and select the point. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a Point: ")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 4009ff78>) (0 . "POINT") (330 . <Entity
name: 40073cf8>) (5 . "267") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (100 . "AcDbPoint") (10 4.27913 8.26876 0.0) (210 0.0 0.0 1.0) (50 . 0.0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 4009ff78>)  -1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "POINT")                      0 - Entity Type

  (5 . "267")                       5 - Handle Name (If handles are turned on)

  (8 . "0")                         8 - Layer Name

  (10 4.27913 8.26876 0.0)          10 - Insertion Point

  (50 . 0.0)                        50 - Angle of the X axis for the UCS in effect when the
                                        point was drawn if PdMode does not = 0  (default = 0)

  (67 . 0)                           67 - Absent or zero indicates the entity is in
                                                                                           model space. If set to 1, paper space.

  (100 . "AcDbEntity")              100 - Ignore      

  (100 . "AcDbPoint")               100 - Ignore        

  (210 0.0 0.0 1.0)                 210 - Ignore extrusion direction

  (330 . <Entity name: 40073cf8>)  330 - Ignore      

  (410 . "Model")                   410 - Layout tab name

)

 

Let's play with it:

(cdr(assoc 10 enlist)) would return (4.27913 8.26876 0.0)

Remember, CDR returns everything after the first item in a list.

To get the insertion point of the Point :

(cdr (assoc 10 enlist)) would return :  (4.27913 8.26876 0.0)

There's not a lot of data associated with a point!


Polyline

Typical DXF Group Codes for a Polyline Entity:

To list a polyline entity in AutoCAD you type LIST<enter> and select the polyline. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a PolyLine: ")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 40222a38>) (0 . "POLYLINE") (330 . <Entity
name: 40073cf8>) (5 . "947") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (100 . "AcDb2dPolyline") (66 . 1) (10 0.0 0.0 0.0) (70 . 4) (40 . 0.0) (41
. 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 . 0) (75 . 6))


Let's take it apart and put it in order:

(

  (-1 . <Entity name: 40222a38>)       -1 - Entity Name

  (0 . "POLYLINE")                                        0 - Entity Type

  (5 . "947")                                                   5 - Handle  (If handles are turned on.)

  (8 . "0")                                                        8 - Layer Name

  (10 0.0 0.0 0.0)                                       10 - Always Zero

  (40 . 0.0)                                                     40 - Default Start Width  (Default = 0)

  (41. 0.0)                                                       41 - Default End Width   (Default = 0)

  (66 . 1)                                                         66 - Vertices follow flag (Always 1 for Polylines)

  (67 . 0)                                                         67 -  Absent or zero indicates the entity is in
                                                                                           model space. If set to 1, paper space.

  (70 . 4)                                                         70 - PolyLine flag
                                                                                           0 =  Default (No flags)                                                                                            1 = This is a closed polyline or mesh closed in M
                                            direction.
                                                                                           2 = Curve fit Vertices have been added
                                                                                           4 = Spline fit Vertices have been added                                                                                            8 = This is a 3D Polyline
                                                                                          16 = This is a 3D polygon Mesh
                                                                                          32 = This polygon Mesh is Closed in the N Direction
                                                                                          64 = This polygon is a polygon Mesh
                                                                                        128 = Generate Line Type Continuously around Vertices

  (71 . 0)                                                         71 - Polygon mesh M vertex count (Optional)

  (72 . 0)                                                         72 - Polygon mesh N vertex count (Optional)

  (73 . 0)                                                         73 - Smooth Surface M Density (Optional)

  (74 . 0)                                                         74 - Smooth Surface N Density (Optional)

  (75 . 6)                                                           75 - Curves and Smooth Surface type (Optional)
                                                                                         0 = No Smooth Surface Fitted
                                                                                         5 = Quandratic B-Spline Surface
                                                                                         6 = Cubic B-Spline Surface
                                                                                         8 = Bezier Surface

  (100 . "AcDbEntity")                              100 - Ignore

  (100 . "AcDb2dPolyline")                   100 - Ignore

  (210 0.0 0.0 1.0)                                   210 - Extrusion Direction (Ignore)

  (330 . <Entity name: 40073cf8>)      330 - Ignore

  (410 . "Model")                                       410 - Tab Layout Name

)

  Notice there are no vertices shown.  You have to step through this entity looking at the sub-entities for the vertices until you come across the SEQEND entity.  Sound familar?  It should.  This is exactly like the Attribute Entity.  Pretty much anyway.  Please read the Attribute section above for instructions on the ENTNEXT function used to step into an entity looking for sub-entities and the SEQEND entity definition.  When you get through, come back to here.

  So, we now know how to step into an entity.  Let's do that for this polyline and save a list of all of the vertices.

(defun C:PTEST()

  ;;;--- Get the entity's name
  (setq en(car(entsel "\n Select a PolyLine: ")))

  ;;;--- Get the DXF group codes of the entity
  (setq enlist(entget en))

  ;;;--- Create an empty list to hold the points
  (setq ptList(list))

  ;;;--- Get the sub-entities name
  (setq en2(entnext en))

  ;;;--- Get the dxf group codes of the sub-entity
  (setq enlist2(entget en2))

  ;;;--- While the polyline has a next vertice
  (while (not (equal (cdr(assoc 0 (entget(entnext en2))))"SEQEND"))

     ;;;--- Get the next sub-entity
     (setq en2(entnext en2))

     ;;;--- Get its dxf group codes
     (setq enlist2(entget en2))

     ;;;--- Check to make sure it is not a spline reference point
     (if(/= 16 (cdr(assoc 70 enlist2)))

       ;;;--- It is a vertex, save the point in a list [ptlist]
       (setq ptList(append ptList (list (cdr(assoc 10 enlist2)))))

     )
  )

  (princ)
)

  If you run this program and then type this in the command line:
  Command: ptList!<enter>

  It will return a list of all of the vertices and will look something like this:

((48.4773 56.3423 0.0) (47.9891 57.1226 0.0) (47.7463 57.7535 0.0) (47.7072
58.2456 0.0) (47.8304 58.6095 0.0) (48.0741 58.8559 0.0) (48.3968 58.9954 0.0)
(48.7568 59.0385 0.0) (49.1125 58.9959 0.0) (49.4264 58.8788 0.0) (49.6767
58.7011 0.0) (49.8457 58.4773 0.0) (49.9157 58.2219 0.0) (49.869 57.9495 0.0)
(49.688 57.6745 0.0) (49.355 57.4114 0.0) (48.8522 57.1748 0.0))

Let's play with it:

Let's get the start point of the polyline from the point list:

(setq startPt(car ptList))

Let's get the end point of the polyline from the point list:

(setq endPt(car(reverse ptList)))

Let's get the area and perimeter of the polyline:

(command "area" "Object" en)
(setq plineArea(getvar "area"))
(setq plinePeri(getvar "perimeter"))

Let's get the Line Type of the polyline:

(if(cdr(assoc 6 enlist))
  (setq plineLtyp(cdr(assoc 6 enlist)))
  (setq plineLtyp "BYLAYER")
)

Let's get the Color of the polyline:

(if(cdr(assoc 62 enlist))
  (setq plineClr(cdr(assoc 62 enlist)))
  (setq plineClr "BYLAYER")
)


Solid

Typical DXF Group Codes for an SOLID Entity:

To list a solid entity in AutoCAD you type LIST<enter> and select the solid. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a Solid: ")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 1cb06d0>) (0 . "SOLID") (5 . "92")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbTrace")
(10 1.0 1.0 0.0) (11 2.0 1.0 0.0) (12 3.0 3.0 0.0) (13 4.0 4.0 0.0)
(39 . 0.0) (210 0.0 0.0 1.0))


Let's take it apart and put it in order:

(

  (-1 . <Entity name:2b80648>)
-1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "SOLID")                                         0 - Entity Type

  (5 . "92")                                                 5 - Handle Name (If handles are turned on)

  (8 . "STR")                                               8 - Layer Name

  (10 1.0 1.0 0.0)                                 10 - First Corner Point

  (11 2.0 1.0 0.0)                                 11 - Second Corner Point

  (12 3.0 3.0 0.0)                                 12 - Third Corner Point

  (13 4.0 4.0 0.0)                                 13 - Fourth Corner Point

            Note: If only three corners are used to define the solid,
                      corner 4 will equal corner 3.


  (39 . 0.0)                                                39 - Thickness. (optional) Default = 0.0

  (67 . 0)                                                     67 - Absent or zero indicates the entity is in
                                                                                model space. If set to 1, paper space.

  (100 . "AcDbEntity")                     100 - Don't worry about this

  (100 ."AcDbTrace")                          100 - Don't worry about this

  (210 0.0 0.0 1.0)                            210 - Don't worry about this Extrusion Factor

)


Let's play with it:

(cdr(assoc 10 enlist)) would return (1.0 1.0 0.0)

Remember, CDR returns everything after the first item in a list.

To get the first corner of the solid :

(cdr (assoc 10 enlist))

To get the second corner of the solid :

(cdr(assoc 11 enlist))

To get the layer name of the solid :

(cdr(assoc 8 enlist))

To see if the entity is indeed a SOLID entity :

(if (= "SOLID" (cdr(assoc 0 enlist)))


Text 

Typical DXF Group Codes for a Text Entity:

To list a text entity in AutoCAD you type LIST<enter> and select the text.  To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a Text Entity: ")))

(setq enlist(entget en))

Would return:

((-1 . <Entity name: 37b0658>) (0 . "TEXT") (5 . "8B") (100 . "AcDbEntity")
(67 . 0) (8 . "STR") (100 . "AcDbText") (10 23.4375 9.1875 0.0) (40 . 0.125)
(1 . "This is some Text!") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "STANDARD")
(71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText")
(73 . 0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name: 37b0658>)  -1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "TEXT")                          0  -  Entity Type

  (1 . "This is some Text!")      1  -  Text Value

  (5 . "8B")                               5   -  Handle Name (If handles are turned on)

  (7 . "STANDARD")                 7  -  Text Style Name

  (8 . "STR")                            8  -   Layer Name

  (10 23.4375 9.1875 0.0)        10  -  Start Point for the text entity

  (11 0.0 0.0 0.0)               Don't worry about this

  (40 . 0.125)                        40  -  Text Height

  (41 . 1.0)                           Don't worry about this width factor.

  (50 . 0.0)                           50  -  Rotation Angle expressed in radians

  (51 . 0.0)                            Don't worry about this oblique angle.

  (67 . 0)                                 Don't worry about this

  (71 . 0)                                 0=Normal   2=Backward  4=Upside Down

  (72 . 0)                                 Don't worry about this.  72 and 73 work together for alignment.

  (73 . 0)                                  Don't worry about this.  72 and 72 work together for alignment.    

  (100 . "AcDbText")             Don't worry about this SubClass Marker

  (100 . "AcDbEntity")           Don't worry about this

  (210 0.0 0.0 1.0)              Don't worry about this Extrusion Factor.

)

Let's play with it:

(cdr(assoc 10 enlist)) would return (23.4375 9.1875 0.0)

Remember, CDR returns everything after the first item in a list.

To get the height of the text :

   (cdr (assoc 40 enlist))

To get the start point of the text :

     (cdr(assoc 10 enlist))

To get the layer name of the text  :

     (cdr(assoc 8 enlist))

To get the text value of the text  :

     (cdr(assoc 1 enlist))

To get the rotation angle of the text  :

     (cdr(assoc 50 enlist))

To see if the entity is indeed a TEXT entity  :

     (if (= "TEXT" (cdr(assoc 0 enlist)))


Trace

Typical DXF Group Codes for a TRACE Entity:

To list a trace entity in AutoCAD you type LIST<enter> and select the trace. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select a TRACE:")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 1cb06f8>) (0 . "TRACE") (5 . "97")
(100 . "AcDbEntity") (67 . 0) (8 . "STR") (100 . "AcDbTrace")
(10 2.0 2.5 0.0) (11 2.0 1.5 0.0) (12 4.0 2.5 0.0) (13 4.0 1.5 0.0)
(39 . 0.0) (210 0.0 0.0 1.0))

Let's take it apart and put it in order:

(

  (-1 . <Entity name:1cb06f8>)
-1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "TRACE")                                       0 - Entity Type

  (5 . "97")                                                 5 - Handle Name (If handles are turned on)

  (8 . "STR")                                               8 - Layer Name

  (10 2.0 2.5 0.0)                                 10 - First Corner Point

  (11 2.0 1.5 0.0)                                 11 - Second Corner Point

  (12 4.0 2.5 0.0)                                 12 - Third Corner Point

  (13 4.0 1.5 0.0)                                 13 - Fourth Corner Point

  (39 . 0.0)                                                39 - Thickness. (optional) Default = 0.0

  (67 . 0)                                                     67 - Absent or zero indicates the entity is in
                                                                                      model space. If set to 1, paper space.

  (100 . "AcDbEntity")                     100 - Don't worry about this

  (100 ."AcDbTrace")                          100 - Don't worry about this

  (210 0.0 0.0 1.0)                             210 - Don't worry about this Extrusion Factor

)


Let's play with it:

(cdr(assoc 10 enlist)) would return (1.0 1.0 0.0)

Remember, CDR returns everything after the first item in a list.

To get the first corner of the trace :

(cdr (assoc 10 enlist))

To get the second corner of the trace :

(cdr(assoc 11 enlist))

To get the layer name of the trace :

(cdr(assoc 8 enlist))

To see if the entity is indeed a TRACE entity :

(if (= "TRACE" (cdr(assoc 0 enlist)))

Note: Notice the resemblance to the SOLID entity. The only difference being,
the TRACE requires FOUR corners to define itself.


XLine

Typical DXF Group Codes for an XLine Entity:

To list an XLine entity in AutoCAD you type LIST<enter> and select the XLine. To do this in AutoLisp you would:

(setq en(car (entsel "\n Select an XLINE:")))
(setq enlist(entget en))


Would return:

((-1 . <Entity name: 40222960>) (0 . "XLINE") (330 . <Entity
name: 40073cf8>) (5 . "92C") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"0") (100 . "AcDbXline") (10 5181.72 4894.2 0.0) (11 0.983723 0.179691 0.0))

Let's take it apart and put it in order:

(

 
(-1 . <Entity name: 40222960>)     -1 - Entity Name (AutoCAD Automatically takes care of this)

  (0 . "XLINE")                                       0 - Entity Type

  (5 . "92C")                                              5 - Handle Name (If handles are turned on)

  (8 . "0")                                                    8 - Layer Name

  (10 5181.72 4894.2 0.0)               10 - First Point (In WCS)

  (11 0.983723 0.179691 0.0)       11 - Unit Direction Vector (In WCS)

  (67 . 0)                                                     67 - Absent or zero indicates the entity is in
                                                                               model space. If set to 1, paper space.

  (100 . "AcDbEntity")                       100 - Ignore

  (100 ."AcDbXline")                            100 - Don't worry about this Subclass marker

  (330 . <Entity name: 40073cf8>)    330 - Ignore

)


Note: There's not much you can do with an XLine.


 End of Entity DXF Group Code Descriptions


AutoLisp Advanced Tutorial

AutoLisp Tutorial

AutoLisp Home

Home

All questions/complaints/suggestions should be sent to JefferyPSanders.com

Last Updated July 31st, 2014

Copyright 2002-2014 JefferyPSanders.com. All rights reserved.