Compare two entities if same

Compare two entities if same

paullimapa
Mentor Mentor
2,223 Views
14 Replies
Message 1 of 15

Compare two entities if same

paullimapa
Mentor
Mentor

Is there a lisp function that would allow me to compare to see if two Entity Names in both cases retrieved using (car(Entsel)) are refer'g to the exact same object in  a given AutoCAD drawing?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Accepted solutions (3)
2,224 Views
14 Replies
Replies (14)
Message 2 of 15

hak_vz
Advisor
Advisor
Accepted solution

Just compare entity handle (code 5).  Handles are unique to each entity

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 15

paullimapa
Mentor
Mentor

Excellent...thanks for the quick reply and solution.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 15

devitg
Advisor
Advisor

@hak_vz ,  Handle is unique , and exclusive . 

2 equal entities  have different Handle , but ir are equal 

So there shall be a way to test for equality. 

 

 

 

 

 

0 Likes
Message 5 of 15

Sea-Haven
Mentor
Mentor

Are they 2

Lines

Same layer

Same angle

Same length

Then yes they are the same but located in different parts of the dwg.

0 Likes
Message 6 of 15

hak_vz
Advisor
Advisor

@Sea-HavenI think @paullimapa  asked for exact same object (entity) and not to compare two objects geometric and other properties. Handle is unique object property that stays  saved in dwg as long as it exist in file, while entity name or 1005 xdata change.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 7 of 15

kpblc2000
Advisor
Advisor
Accepted solution
(setq a (car (ensel)) b (car (entsel)))

(equal (entget a '("*")) (entget b '("*")))

:?:

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

Message 8 of 15

paullimapa
Mentor
Mentor

This is another excellent solution...thanks.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 15

devitg
Advisor
Advisor
Accepted solution

Hi,  , i do not understand  how, 2 "LIKE THE SAME" can give the same entity name .

Only if you pick at the REALLY same ent it will give T for equal. 

Neither need to compare the ENTGET. just compare a b 

 

 

(setq a (car (entsel)))
(setq b (car (entsel)))

(equal a b)

 

 Will be T if user pick twice at the SAME ent  

Maybe the OP , need to know if the user pick twice at the same ENT.

 

 

 

Message 10 of 15

paullimapa
Mentor
Mentor

yep, that worked too.

I think my mistake was using the wrong function

I used "=" but that only works for #s

I should be using "equal" which is what works.

Thanks for your input...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant
[never mind]
Kent Cooper, AIA
Message 12 of 15

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

....

I used "=" but that only works for #s

I should be using "equal" which is what works.

....


[Just for future reference, (=) also works with text strings.  And (eq) works as well as (equal) in this case.]

Kent Cooper, AIA
Message 13 of 15

paullimapa
Mentor
Mentor

you are correct...that's why I've used = so much because it also works with strings.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 15

paullimapa
Mentor
Mentor

found this thread of another using = instead of equal

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/compare-entity-names/td-p/2422897 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 15

devitg
Advisor
Advisor

My not-twice way 

 

(SETQ A (CAR (ENTSEL)))


(SETQ OTHER (NOT-TWICE A))


(DEFUN NOT-TWICE  (A / B)

  (SETQ B (CAR (ENTSEL)))

  (IF (EQUAL A B)
    (PROGN
      (ALERT "you pick the same entity")
      (NOT-TWICE A)
      )
    )
  B
  )


0 Likes