Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(car (entsel)) convert to a string.

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
mdhutchinson
3428 Views, 10 Replies

(car (entsel)) convert to a string.

Is there any way to convert an entity name to a string?

10 REPLIES 10
Message 2 of 11
hmsilva
in reply to: mdhutchinson

(vl-prin1-to-string (car (entsel)))

HTH

Henrique

EESignature

Message 3 of 11
mdhutchinson
in reply to: hmsilva

Yep... you took the words right out of my mouth... I just found it.

 

Thanks!...

Message 4 of 11
_Tharwat
in reply to: mdhutchinson

May I know what is the need of converting an entity name to string ?

Message 5 of 11
mdhutchinson
in reply to: _Tharwat

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.

Message 6 of 11
hgasty1001
in reply to: mdhutchinson

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

 

 

 

Message 7 of 11
Kent1Cooper
in reply to: mdhutchinson


@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

 

Kent Cooper, AIA
Message 8 of 11
Lee_Mac
in reply to: Kent1Cooper

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"

 

Message 9 of 11
john.uhden
in reply to: mdhutchinson

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

Message 10 of 11
stevor
in reply to: hmsilva

 

 ; 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.

S
Message 11 of 11
Kent1Cooper
in reply to: stevor


@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.]

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost