Extracting Subentity Names with autolisp in AutoCAD

Since there are times when we need to access parts of polylines and blocks, we will need to get to the subentities using (entnext) and (nentsel).

Explanation: (entnext) with polylines

(entnext [entity name])

(entnext) takes as its argument an entity name and returns the entity name of the next entity or subentity. If we execute the following function and pick a polyline, the entity name returned refers to the main entity:

Command: (setq PNAME (GETNAME))
<Entity name: <60000018>

  • Executing (entnext) with the entity name of a main entity such as a polyline as its argument returns a subentity name:

Command: (setq VERTEX1NAME (entnext PNAME))
<Entity name: <60000030>

The entity name above refers to the first subentity of the complex entity, in this case the first vertex of the pline.

  • Executing the (entnext) function using the name of a subentity returns the name of the next subentity:

Command: (setq VERTEX2NAME (entnext VERTEX1NAME))
<Entity name: <60000048>

Thus if the argument is the name of the main entity, the first subentity is returned, and if the argument is a subentity, the next subentity is returned.

  • As always, (entnext) with no argument returns the first non-deleted entity in the database.

The SEQEND Subentity

There is a special subentity type called SEQEND, which indicates the end of the list of subentities. The SEQEND is useful when processing a list of subentities. A polyline with three vertices, for example, will have a main entity, three subentities with entity type “VERTEX”, and a fourth subentity, its “SEQEND”:

See also  Accessing Subentities without User Input with autolisp in AutoCAD

Command: (setq SEQNAME (entnext VERTEX3NAME))
<Entity name: <60000078>

This subentity name refers to the SEQEND.

  • (entnext) with the entity name of a SEQEND or non-complex entity as its argument returns the name of the next main entity in the database.
  • Note that SEQEND is spelled without a “u” after the “q”.

Obtaining Entity Definition Lists of Subentities

So far we have only extracted the name of the subentity. To obtain further information about the subentity, use (entget) with the subentity name as the argument:

Command: (entget VERTEX1NAME)
((-1 . <Entity name: 60000048>) (0 . “VERTEX”) (8 . “0”)
(105.05.00.0)(40.0.0)(41.0.0)(42.0.0)(70.0) (50 . 0.0))

Notice that DXF code 0, entity type, is associated with the string “VERTEX”. Other DXF codes indicate position, starting and ending width, and other properties relating to bulge and curvature, depending on how the polyline was created.

The entity definition list of a SEQEND is different from that of a vertex:

Command: (entget SEQNAME)
((-1 . <Entity name: 60000078>) (0 . “SEQEND”) (8 . 0) (-2 . <Entity name: 60000018>))

In addition to the entity name of the subentity, its entity type and the layer, this list returns the entity name of the main entity, associated with DXF code -2.

Back to top button