TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: A_LOTA_NOTA on July 16, 2007, 08:47:27 PM

Title: How to compare entity name?
Post by: A_LOTA_NOTA on July 16, 2007, 08:47:27 PM
How could I compare entity names to make sure they are not equal? If I wanted to test to see if the were equal I could use (eq Ent1 Ent2) & get "T" but (/= Ent1 Ent2) I also get "T"!
Title: Re: How to compare entity name?
Post by: Adesu on July 16, 2007, 09:01:34 PM
Hi A_LOTA_NOTA ,
I think you want like this.
Code: [Select]
(defun c:test (/ ss1 ss2)
  (setq ss1 (car (entsel "\nSelect an object first")))
  (setq ss2 (car (entsel "\nSelect an object second")))
  (if
    (eq ss1 ss2)
    (alert "\nThis object is same entity")
    )  ; if
  (if
    (not (eq ss1 ss2))
    (alert "\nThis object is not same entity")
    )  ; if
  (princ)
  )

How could I compare entity names to make sure they are not equal? If I wanted to test to see if the were equal I could use (eq Ent1 Ent2) & get "T" but (/= Ent1 Ent2) I also get "T"!
Title: Re: How to compare entity name?
Post by: gile on July 17, 2007, 02:45:51 AM
Hi,

You have to use eq or equal function, = and /= only work with numbers or strings.
Title: Re: How to compare entity name?
Post by: ronjonp on July 17, 2007, 10:45:15 AM
This should do it:

Code: [Select]
(if (eq (car (entsel)) (car (entsel)))
  (alert "same")
  (alert "not same")
)