Is there any way to convert an entity name to a string?
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Yep... you took the words right out of my mouth... I just found it.
Thanks!...
May I know what is the need of converting an entity name to string ?
okay... perhaps you might think of a better way.
Without going into great detail...
I have the entity name... but if the object was deleted the entity name can't tell me what type of object it was.
I thought about saving it to a list by type of object... then I could know what type it was.
Hi,
One way to do that is writing the entity names to a file and reading that file, something like:
(setq fp (open "c:/somedir/entnames.txt" "a"))
(setq ename (cdr assoc -1 (entget(car(entsel)))))
(print ename fp)
(close fp)
So, you have the entity names in a file you can read in.
Now i have to ask you why do you need entity names in a file?, it's more easy to store handles as they are persistent, and string entity names can not be converted to real entity names.
Gaston Nunez
@mdhutchinson wrote:
....
I have the entity name... but if the object was deleted the entity name can't tell me what type of object it was.
I thought about saving it to a list by type of object... then I could know what type it was.
You don't need to convert the entity name to a string to do that. You can put it into such a list as an entity name, and even if the entity is deleted, you can still find the name in the list. You could put it into a list of paired-entity-name-and-type sublists:
(setq ename (entlast)); happens to be a Circle in this test
<Entity name: 7efb3c28>
(setq etypelist (list (list ename (cdr (assoc 0 (entget ename))))))
((<Entity name: 7efb3c28> "CIRCLE")); this list would presumably also have other such sub-lists in it
(entdel ename); delete it
Then, even after it's gone:
(assoc ename etypelist)
(<Entity name: 7efb3c28> "CIRCLE")
or
(cdr (assoc ename etypelist))
("CIRCLE")
Or, you could put it into a list by entity type:
(setq Circles (cons ename Circles))
(<Entity name: 7efb3c28>); this list would presumably also have other Circle entity names in it
(entdel ename); delete it
Then, even after it's gone:
(member ename Circles)
(<Entity name: 7efb3c28>); it's in there
Since the entdel function simply toggles the erase flag of the entity, an alternative solution could be to temporarily 'unerase' the entity to retrieve the required data, avoiding the need to store lists:
(defun etype ( e / x ) (or (setq x (entget e)) (and (setq x (entget (entdel e))) (entdel e)) ) (cdr (assoc 0 x)) )
Example:
_$ (setq ent (car (entsel))) <Entity name: 7ef03c20> _$ (etype ent) "ARC" _$ (entdel ent) <Entity name: 7ef03c20> _$ _$ (etype ent) "ARC"
I'm sorry, but I don't see any point to it.
Save the handle and use (handent) to retrieve the entity name.
But to me it's sorta like saving your dead dog's favorite toy. What for?
John F. Uhden
; Entity name from dxf 0 without title, scg 3JAN17
(Defun EN_S (EN / S) (setq S (vl-prin1-to-string EN))
(substr S 14 (- (strlen S) 14)) )
Thanks, Henrique.
Hate to think why I did not do this sooner.
@stevor wrote:
; Entity name from dxf 0 without title, scg 3JAN17
(Defun EN_S (EN / S) (setq S (vl-prin1-to-string EN))
(substr S 14 (- (strlen S) 14)) ).....
[That may technically do what they Subject line says (though replacing the 14's with 15 gets it without a leading space, for me here in Acad2016). But it doesn't serve the need described in Post 5 -- it's not going to be possible to get any information about an entity, type-of-object or otherwise, from a string-conversion of its entity name. I can't think of anything useful you could actually do with such a thing, but maybe I lack sufficient imagination.]