Entity Name Functions
 
 
 

To operate on an object, an AutoLISP application must obtain its entity name for use in subsequent calls to the entity data or selection set functions. Two functions described in this section, entsel and nentsel, return not only the entity's name but additional information for the application's use.

Both functions require the AutoCAD user to select an object interactively by picking a point on the graphics screen. All the other entity name functions can retrieve an entity even if it is not visible on the screen or if it is on a frozen layer. The entsel function prompts the user to select an object by picking a point on the graphics screen, and entsel returns both the entity name and the value of the point selected. Some entity operations require knowledge of the point by which the object was selected. Examples from the set of existing AutoCAD commands include: BREAK, TRIM, and EXTEND. The nentsel function is described in detail in Entity Context and Coordinate Transform Data. These functions accept keywords if they are preceded by a call to initget.

The entnext function retrieves entity names sequentially. If entnext is called with no arguments, it returns the name of the first entity in the drawing database. If its argument is the name of an entity in the current drawing, entnext returns the name of the succeeding entity.

The following code fragment illustrates how ssadd can be used in conjunction with entnext to create selection sets and add members to an existing set.

(setq e1  (entnext))
(if  (not e1)				; Sets e1 to name of first entity.
  (princ "\nNo entities in drawing. ") 
  (progn
	(setq ss  (ssadd))	 ; Sets ss to a null selection set.
	(ssadd e1 ss)			; Returns selection set ss with 
							 ; e1 added.
	(setq e2 (entnext e1))   ; Gets entity following e1.
	(ssadd e2 ss)			; Adds e2 to selection set ss.
  )
)

The entlast function retrieves the name of the last entity in the database. The last entity is the most recently created main entity, so entlast can be called to obtain the name of an entity that has just been created with a call to command.

You can set the entity name returned by entnext to the same variable name passed to this function. This “walks” a single entity name variable through the database, as shown in the following example:

(setq one_ent (entnext))			; Gets name of first entity.


 (while one_ent 
 . 
 .								; Processes new entity.
 . 
  (setq one_ent (entnext one_ent))
)								 ; Value of one_ent is now nil.