Back to AutoLisp Advanced Tutorial HomePage Back to AutoLisp Tutorial HomePage
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: 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. 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))) 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 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>) 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 (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> 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") 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))) Typical DXF Group Codes for an ELLIPSE Entity: ;;;--- Save the center point of the ellipse ;;;--- Save the endPoint of the major axis
relative to center pt ;;;--- Create a new point on the end of the major axis ;;; by subtracting code 10
point from code 11 point ;;;--- Finally, find the major axis length To list an image entity in AutoCAD you type LIST<enter> and select the image. To
do this in AutoLisp you would: ((-1 . <Entity name: 40073da8>) (0 . "IMAGE") (330
. <Entity 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 (12 7.95199e-020 0.0012987 0.0) 12 -
V-vector of a single pixel (points along the visual left (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) (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) 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 : (setq y(cadr(cdr(assoc 13 enlist)))) To get the layout Tab name : Typical DXF Group Codes for an INSERT Entity: 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") 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))) Typical DXF Group Codes for an LWPOLYLINE Entity: (setq enlist(entget en))
FLAGS:
Here's an example: 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 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 (70 . 0) 70 - Justification: 0 = Top, 1 = Zero, 2 = Bottom (71 . 3)
71 - Flags - 1=Unlocked 2=Closed (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. Here's an example of how to get all of the vertices in a list:
(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 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 Typical DXF Group Codes for an MText Entity: ((-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 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 (71 . 1)
71 - Attachment point 1=Top
2=Top Center (72 . 5)
72 - Drawing Direction 1 = Left to Right (73 . 1)
73 - Line Spacing Style (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: 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 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 . (3 . 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))) Typical DXF Group Codes for an Point or Node Entity: ((-1 . <Entity name: 4009ff78>) (0 . "POINT") (330
. <Entity 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 (67 . 0)
67 - Absent or zero indicates the entity is in (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: There's not a lot of data associated with a point! Typical DXF Group Codes for a Polyline Entity:
( (-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 (70 . 4)
70 - PolyLine flag (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) (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 (princ) If you run this program and then type this in the command line: 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 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) Let's get the Line Type of the polyline: (if(cdr(assoc 6 enlist)) Let's get the Color of the polyline: (if(cdr(assoc 62 enlist)) Typical DXF Group Codes for an SOLID Entity: 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") 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))) Typical DXF Group Codes for a TRACE Entity: Typical DXF Group Codes for an XLine Entity: (330 . <Entity name: 40073cf8>)
330 - Ignore End of Entity DXF Group Code Descriptions All questions/complaints/suggestions should be sent to / Last Updated March 30th, 2016 Copyright 2002-2016 /. All rights reserved. |