The AutoLisp Intermediate Tutorial
Entity Functions
entget entlast entnext entdel entmod entupd Example Program
entget - This function returns the DXF Group Codes of the entity.
Syntax : (entget ename)
ename - a valid entity name returned by entsel, ssname, entlast, or the entnext function.
Returns an Entity's DXF Group Codes as an association list.
(setq en(car(entsel))) returns entity name as eg. <Entity name: 3b40a60>
(entget en) returns :
((-1 . <Entity name: 3b40a60>) (0 . "LINE") (5 . "FC") (100 . "AcDbEntity") (67 . 0) (8 . "DIM") (100 . "AcDbLine") (10 252.578 68.25 0.0) (11 188.379 31.5 0.0) (210 0.0 0.0 1.0))
entlast - This function returns the name of the last non-deleted entity in the drawing.
Syntax : (entlast)
This function is mainly used to get the last entity added to the drawing.
Returns an entity name.
(entlast) returns <Entity name: 3b40a60>
entnext - Let's look at
AutoDesk's explanation: If entnext is called with no arguments, it returns the
entity name
of the first nondeleted entity in the database. If entnext is called with an entity name
argument ename, it
returns the entity name of the first nondeleted entity following ename in the database. If
there is no next
entity in the database, it returns nil. The entnext function returns both main entities
and subentities.
The entities selected by ssget are main entities, not attributes of blocks or vertices of polylines. You can access the internal structure of these complex entities by walking through the subentities with entnext. Once you obtain a subentity's name, you can operate on it like any other entity. If you obtain the name of a subentity with entnext, you can find the parent entity by walking forward with entnext until a seqend entity is found, then extracting the -2 group from that entity, which is the main entity's name.
Syntax : (entnext) or (entnext ename)
ename - a valid entity name returned by entsel, ssname, entlast, or the entnext function.
(entnext) returns the name of the first entity in the drawing.
(entnext ename) returns the name of the next entity following ename.
entdel - This function deletes an entity from the drawing if it exist. If it does not exist and has been previously deleted, it will undelete the entity.
Syntax : (entdel ename)
ename - a valid entity name returned by entsel, ssname, entlast, or the entnext function.
Returns an entity name.
(setq en(car(entsel))) returns the name of selected entity.
(entdel en) deletes the entity and returns the name of the deleted entity.
(entdel en) undeletes the entity and returns the name of the undeleted entity.
entmod - Modifies an entity in the AutoCAD database.
Syntax : (entmod elist)
elist - a list that is returned from an entget statement. (DXF Group Codes of an entity)
Returns an elist if successful otherwise it returns nil.
(setq en(car(entsel))) returns the name of selected entity.
(setq elist(entget en)) returns the DXF Group Codes of the entity.
(setq elist(subst (cons 8 "DIM")(assoc 8 elist) enlist))
The line above Replaces existing layer name in the elist with new layer name "DIM"
(entmod elist) updates the AutoCAD database and replaces the old layer name with the new one.
entupd - Updates the screen image of an entity.
Syntax : (entupd ename)
ename - a valid entity name returned by entsel, ssname, entlast, or the entnext function.
Returns an entity name.
(setq en(car (entsel))) returns an entity name.
(entupd ename) refreshes the entity on the graphics screen.
Note: If you modify the DXF Group Codes of an entity, such as changing the layer (8 . "LAyerName"), you will not notice the change until you regenerate the entire drawing or use entupd to regenerate the entity.
End of Entity Functions
Example Program 1:
Let's change an entity's layer to a layer named "DIM".
(defun C:CLay()
(if(setq ent(entsel))
(progn
(setq en(car ent))
(setq enlist(entget en))
(setq enlist (subst (cons 8 "Dim")(assoc 8 enlist)enlist))
(entmod enlist)
(entupd en)
)
(alert "Error - Select an entity please.")
)
(princ)
)
Execution:
Command: (load "CLay")<enter>
Command: CLay<enter>
Command: Select Object:<pick>
Command: