Try NENTSEL. It's like ENTSEL but instead of returning a list of the main entity's name (if you're clicking on an attribute that would be the entity name of the INSERT to which it's attached) and the pick point it returns the entity name of the selected sub-entity (if you click on an ATTRIB that would be the entity name of the ATTRIB itself) and the pick point. If I do
(setq return_value (nentsel))
AutoCAD prompts
Select object:
Then when I click on the ELEV attribute of an old-school DCA POINT block in this drawing on my screen it returns this list
(<Entity name: -7d8390> (428227.0 1.29808e+006 0.0))
(car return_value) returns
<Entity name: -7d8390>
and (entget (car return_value)) returns the entity data for the POINT attribute:
((-1 . <Entity name: -7d8390>) (0 . "ATTRIB") (330 . <Entity
name: -7d8398>) (5 . "57836") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8
. "elev") (100 . "AcDbText") (10 428224.0 1.29808e+006 0.0) (40 . 0.8) (1 .
"8.182373") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "S6") (71 . 0) (72 . 0) (11
0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttribute") (2 . "ELEV") (70 . 0)
(73 . 0) (74 . 0) (280 . 0))
which you can modify with ENTMOD, as well as reading information from the entity data.
So supposed I want to reset the value of the selected attribute to "101.25".
(defun test()
(setq return_value (nentsel))
(setq attribute_name (car return_value))
(setq attribute_data (entget attribute_name))
(setq revised_attribute_data
(subst
(cons 1 "101.25")
(assoc 1 attribute_data)
attribute_data
)
)
(entmod revised_attribute_data)
(entupd attribute_name)
)
The last ENTUPD line is not strictly necessary, as the attribute value was updated by the previous ENTMOD line, but you wouldn't see the change on the screen until you REGEN the drawing. Also, in a real program you want to do some checking to make sure you selected something and that what you selected was an ATTRIB rather than some other kind of entity.