Get Entity name of a non selected object

Get Entity name of a non selected object

msarqui
Collaborator Collaborator
499 Views
3 Replies
Message 1 of 4

Get Entity name of a non selected object

msarqui
Collaborator
Collaborator

Hello guys

 

May I have your help, please?

 

I found this post that provide the way to get the Entity name of all objects of a selected block.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-acces-entities-within-a-block...

 

Lets say I have a block with five attributes named: XX, XXX, XXXX, ##1 and ##2. If I use one of the solutions from the post above, I will have a list of all Entity names in that block. My question is, how can I have the Entity name of a specific object in that block. In my case, it will be the ##2 attribute?

 

But, here it comes the tricky question...The selection of the block must be performed by a NENTSEL on the ##1 attributte. FYI, the block is also dynamic...

 

Please, see attached the block

Thanks,

Marcelo

0 Likes
Accepted solutions (1)
500 Views
3 Replies
Replies (3)
Message 2 of 4

hmsilva
Mentor
Mentor
Accepted solution

Hi Marcelo,

try

 

(defun c:demo (/ ent ent1 hnd hnd1 my_att_ename nsel)
    (if (and (setq nsel (nentsel "\nSelect ##1 attribute: "))
             (= (length nsel) 2)
             (setq ent1 (entget (car nsel)))
             (= (cdr (assoc 0 ent1)) "ATTRIB")
             (= (cdr (assoc 2 ent1)) "##1")
             (setq hnd1 (cdr (assoc 330 ent1)))
             (setq ent (entget hnd1))
             (setq hnd hnd1)
        )
        (while (not (eq (cdr (assoc 0 ent)) "SEQEND"))
            (setq hnd (entnext hnd))
            (setq ent (entget hnd))
            (if (equal (cdr (assoc 2 ent)) "##2")
                (setq my_att_ename hnd)
            )
        )
        (prompt "\nYou didn't select ##1 attribute... ")
    )
    (if my_att_ename
        (progn
            (princ "\nThe attribute ##2 ename is : ")
            (princ my_att_ename)
        )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 4

msarqui
Collaborator
Collaborator
Many thanks Henrique!
I can manage from here.
Marcelo
0 Likes
Message 4 of 4

hmsilva
Mentor
Mentor

@msarqui wrote:
Many thanks Henrique!
I can manage from here.
Marcelo

You're welcome, Marcelo!
Glad I could help

Henrique

EESignature

0 Likes