Lesson 26 – How to obtain the entity name of any object in a drawing

In this section we will see how to select and change individual objects from AutoCAD’s database without having to select them at a command prompt. To do this, we need to select the entity name of an object. This entity name is stored in an entity definition list.

There are several methods of selecting entity names, depending on which object you want. In most cases you will be running a loop that will go through a specified selection of entity names and you won’t even see it happen.

Explanation: the (entxxx) functions
(entnext)
         (entnext [ename])
The (entnext) function, if called with no argument, returns the entity name of the first nondeleted entity in the drawing. If (entnext) is used with the optional ename argument, it will give the entity name of the first nondeleted entity following ename in the drawing. If there is no next entity, (entnext) returns nil.

Command: (setq E1 (entnext))
          <Entity name: 60000014>
Command: (setq E2 (entnext E1))
          <Entity name: 60000020>

  • What function can be used to determine the data type of what (entnext) returns?
  • Ename is a new datatype made of a list of the entity name and a point list.
  • You should always include a (setq) in front of the entity selection tools so you can access the entity again.

(entlast)

The (entlast) function returns the entity name of the last nondeleted entity in the drawing. This function is often used to select an entity just drawn using the (command) function.

(entdel)
         (entdel ename)

The (entdel) function deletes the named entity without picking. This function is used when an entity must be drawn, then some calculation or command uses the entity (such as DIVIDE or MEASURE), and then the entity must be erased. It is more reliable than starting the ERASE command and picking a point on the entity.

(entsel)
          (entsel [prompt])

The (entsel) function provides a means of prompting the user to select any desired entity by picking. It returns a two-element list containing the entity name and the pick-point where it was selected. If the optional prompt string argument is not specified, the default prompt is “Select object:”

Command: (entsel)
Select object: <pick object>
(<Entity name: 60000014> (3.0 3.0 0.0))

  • What type of data does (entsel) return?
  • What function can be used to extract the first element?

PRACTICE

Use the first three functions shown above to name several entities in a drawing. Estimated time for completion: 5 minutes.

1. Open the drawing LISPA1.DWG.

2. Use the (entnext) function to name your first entity “ENT1” and the second entity “ENT2.”

3. Use (entsel) to name any two entities “ENT3” and “ENT4.” Be sure to extract only the entity name from the (entsel) function.

4. Use (entlast) to name the last entity drawn “ENT5.”

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons
SUBSCRIBE TO OUR NEWSLETTER

It's FREE!

Sign up and receive an email every time a new tutorial is published