Function Definitions

 16  -  Entity Access

entlast ..... Returns the last entity name in the database.  The entity will be a main entity, and must not have been deleted.

(entlast)  returns the name of the last entity in the database

This entity name can be submitted to entget to obtain a full description of the entity.  See entget below.

Often used to obtain the name of an entity just created with the command function.

This entity name can be fed to AutoCAD whenever it is prompting for general object selection.  See example below under entnext. 


entnext ..... Returns an entity name (main entity or sub-entity) from the database

(entnext)  returns the name of the first entity in the database
(entnext en)  returns the name of the next entity after the entity identified by the variable en.  If en is the last entity in the database, entnext returns nil.

This entity name can be fed to AutoCAD whenever it is prompting for general object selection.  For example, after entering ERASE and being prompted to select objects, you could enter !en1 (assuming you have assigned an entity name to variable en1).  The name can also be used inside a command function -- (command ".erase" en1 "").

Entity names do not carry over to subsequent editing sessions, but entity handles do.


entsel ..... Returns both an entity name (selected with the pointer using a "pickbox" or with coordinates) and the point at which the entity was selected.

(entsel "Pick the entity. ")  returns a list with 2 elements:  the entity name and the coordinates of the point at which the entity was selected.  You can retrieve the entity name from this list with car and the point with cadr.  If no prompt is specified, a default prompt, "Select object: ", is displayed.


nentsel ..... If a simple entity is selected, returns the same information as entsel.  If a complex entity is selected (polyline or block), additional information about the sub-entity selected is returned.

nentselp ..... Returns the same as nentsel, but accepts an optional second argument specifying a point so that no user input is needed.

entget ..... Returns an association list which defines an entity

(entget en)  retrieves the entity identified by the variable en in the form of an association list which uses codes similar to (but not identical to) AutoCAD's DXF group codes

A few sample association lists are given below.  A "verbal" description of the entity is given first, then the AutoLISP description in the form of the returned association list.  These association lists are not complete; they contain only key elements for illustrative purposes.

A line on Layer2 from 0,2 to 1,3
((-1 . <Entity name: #######>) (0 . "LINE") (8 . "LAYER2") (10 0.0 2.0 0.0) (11 1.0 3.0 0.0))
A circle at 3,2 with radius = .75
((-1 . <Entity name: #######>) (0 . "CIRCLE") (8 . "LAYER4") (10 3.0 2.0 0.0) (40 . 0.75))
An arc on layer Hidden, centered at 5,6 with radius = .5, from 0° - 90°
((-1 . <Entity name: #######>) (0 . "ARC") (8 . "HIDDEN") (10 5.0 6.0) (40 . 0.5) (50 . 0.0) (51 . 1.5708))
Text on layer 0, at 1,8, height .4, angle 15°(.261799 radians), "Dr. Pepper"
((-1 . <Entity name: #######>) (0 . "TEXT") (8 . "0") (10 1.0 8.0 0.0) (40 . 0.4) (1 . "Dr. Pepper") (50 . 0.261799) (41 . 1.0) (51 .0.0) (7 . "STANDARD") (71 . 0) (72 . 0) (11 0.0 0.0 0.0)   ----   Codes:  41 = width factor, 51 = obliquing angle, 7 = style name, 71 = upside down/backwards, 11 = endpoint if right justified
A 3dface from 1,1,0 to 2,1,0 to 2,1,1 to 1,1,1
((-1 . <Entity name: #######>) (0 . "3DFACE") (8 . "2") (10 1.0 1.0 0.0) (11 2.0 1.0 0.0) (12 2.0 1.0 1.0) (13 1.0 1.0 1.0))
When you need to know what any particular entity's association list looks like, draw the entity, then enter (entget (entlast)) at the command prompt.

Each sublist contains a group number - for example, 8 for layer, 40 for radius or text height, etc.  By using the cdr and assoc functions, a value associated with a specified group number can be retrieved.  For example, if the above association list for the circle has been set to variable el,

(assoc 40 el)  returns (40 . 0.75)
(cdr (assoc 40 el))  returns 0.75
(assoc 10 el)  returns (10 3.0 2.0 0.0)
(cdr (assoc 10 el))  returns (3.0 2.0 0.0)

Notice that the cdr of a dotted pair returns an atom, not a list.


entmod ..... Modifies an entity by changing the database according to an altered association list.  The association list is in the same form as that received from the entget function.

(entmod elnew)  Assuming the association list elnew has been modified by use of the subst function, this entmod function modifies the database to conform with the changes as they now exist in elnew.


entupd ..... Updates (regenerates) a modified entity on the screen.  Applies to polyline vertices or block attributes.

(entupd en)  updates the entity en


entdel ..... Deletes or restores an entity.  Works only on main entities.

(entdel en)  deletes the entity identified by the variable en (or restores it if it was deleted earlier in the same editing session).


entmake ..... Creates a new entity from an association list in the form returned from entget

(entmake '((0 . "CIRCLE") (10 2.25 3.25 0.0) (40 . 0.75)))  creates a circle at 2.25, 3.25 with a radius of 0.75.  Since the layer, color, and linetype are not specified, they are set to the current layer, color, and linetype.


handent ..... Uses an entity's handle to get the entity's name.  Entity names differ from one editing session to the next. However, entity handles remain the same across editing sessions.

After assigning a handle (hex ID number) to variable eh,
(handent eh)  returns the name of the entity in the current editing session, whether the entity has been deleted or not


textbox ..... Returns diagonal corners of a box surrounding a text entity.  The text entity can be existing or "proposed."

After placing text in the drawing, then using (setq el (entget (entlast))) to assign the text's association list to variable el,
(textbox el)  returns a list containing two points which are the lower left and upper right corners of the box surrounding the text, as though the text were at zero rotation and inserted at 0,0,0.  The textbox function takes into account the font and style used by the text, as well as whether the particular text string contains letters that descend below the baseline.

To analyze proposed text before placing it in a drawing, submit an association list (including at least the text string) to the textbox function in the following form:
      (textbox '((1 . "Put your text here")))
If only the text string is submitted as illustrated above, the textbox function adopts the current setting for such things as style (and its associated font, width factor, obliquing angle, etc.), and height.  Or, these can be explicitly defined in the association list submitted to textbox.


HOME


Copyright © 1988, 1998 Ronald W. Leigh