checking type of entity

checking type of entity

Ranjit_Singh
Advisor Advisor
1,101 Views
14 Replies
Message 1 of 15

checking type of entity

Ranjit_Singh
Advisor
Advisor

I select an entity and then want the code to identify if it is a Line, Polyline or Lwpolyline and do something. Is this the cleanest way to check for that condition or can I somehow make it concise? Thanks.

(OR (= (cdr (assoc 0 ll)) "LINE") (= (cdr (assoc 0 ll)) "LWPOLYLINE") (= (cdr (assoc 0 ll)) "POLYLINE"))
0 Likes
Accepted solutions (1)
1,102 Views
14 Replies
Replies (14)
Message 2 of 15

Satoews
Advocate
Advocate
(IF (EQ ((cdr (assoc 0 ll)) "LINE,POLYLINE,LWPOLYLINE")))

should be able to do something like this.

Shawn T
0 Likes
Message 3 of 15

Ranjit_Singh
Advisor
Advisor

Thanks!

0 Likes
Message 4 of 15

Satoews
Advocate
Advocate

no problem, glad I can be of help Smiley Happy

Shawn T
0 Likes
Message 5 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@Tornac wrote:
(IF (EQ ((cdr (assoc 0 ll)) "LINE,POLYLINE,LWPOLYLINE")))

should be able to do something like this.


The (eq) function doesn't accept comma-delimited alternative strings.  [And there are some extra parentheses in there.]  I suspect you really mean:

(if (wcmatch (cdr (assoc 0 ll)) "LINE,POLYLINE,LWPOLYLINE")

 

which could also be just:

 

(if (wcmatch (cdr (assoc 0 ll)) "LINE,*POLYLINE")

 

Kent Cooper, AIA
Message 6 of 15

Satoews
Advocate
Advocate

Ugh, so eq would work for single, wcmatch works for single and multi. Would = work in this case too or would or just wcmatch?

Shawn T
0 Likes
Message 7 of 15

Ranjit_Singh
Advisor
Advisor

Thanks Kent! I realized right after I tried the code that it didn't work. Thanks for the correct code.

0 Likes
Message 8 of 15

Satoews
Advocate
Advocate
 
Shawn T
0 Likes
Message 9 of 15

scot-65
Advisor
Advisor
And another way...
(member (cdr (assoc 0 ll)) '("LINE" "POLYLINE" "LWPOLYLINE"))

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 10 of 15

Satoews
Advocate
Advocate
  (setq lst '("LWPOLYLINE" "POLYLINE" "LINE"))
  (setq no 0)
    (repeat (length lst)
      (if (eq (cdr (assoc 0 ll)) (nth no lst))
       (whatever you command is. . .))
       (setq no (1+ no)))

Wanted to see if I could do it with eq, this seems to work for me. Obviously not the least amount of code though =P

Shawn T
0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

@Tornac wrote:

Ugh, so eq would work for single, wcmatch works for single and multi. Would = work in this case too or would or just wcmatch?


Help will tell you all about the different comparison functions.  Some of the more meaningful differences:

(wcmatch) is only about text strings, whereas (=) and (eq) and (equal) can compare more kinds of things.

 

(equal) allows a fuzz factor when comparing numerical values.

 

(=) can compare any number of items for equality among all of them, whereas (eq) and (equal) can compare only two.  (wcmatch) also compares only two, though not really two items, but rather one actual string and one string pattern to test it against [which can contain multiple comma-separated patterns within one pattern string].

 

(wcmatch) allows wildcards [that's what the 'wc' in the function name stands for], but none of those other functions do.  (wcmatch)'s pattern format, including wildcards, works in (ssget) filter lists such as for entity type or Layer or text-content entries.

Kent Cooper, AIA
Message 12 of 15

Satoews
Advocate
Advocate

Thanks for the explanation kent! Help only goes so far in explaining so its really nice to get your incite.

Shawn T
0 Likes
Message 13 of 15

Satoews
Advocate
Advocate

After kents post i wanted to see how = would work as well. 

 

(if (= (OR (cdr (assoc 0 ll)) "POLYLINE" "LWPOLYLINE" "LINE"))

Alot less than eq =P

Shawn T
0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@Tornac wrote:

After kents post i wanted to see how = would work as well. 

 

(if (= (OR (cdr (assoc 0 ll)) "POLYLINE" "LWPOLYLINE" "LINE"))

....


Actually, that's not a valid construction for the purpose.  The result of the (or) function is the only thing supplied to the (=) function, and if an (=) function is supplied only one argument, it returns T, even if that one argument is nil.  But it won't be anyway -- since the (or) function includes some things that are not nil [the text strings, no matter what they actually say, even if they have nothing to do with entity type names], it will always return T, so the (=) function will also always return T, no matter what the entity type is.  If the entity is an Arc, that's equivalent to the (if) function checking whether or not:

 

(= (or "ARC" "POLYLINE" "LWPOLYLINE" "LINE"))

 

which returns T, as it also would if the entity were of any other type at all.

 

I think the only way to do this with a combination of (=) and (or) would be as in Post 1, though you could shorten that a little by putting (cdr (assoc 0 ll)) into a variable, instead of spelling it out separately within each (=) function.

Kent Cooper, AIA
Message 15 of 15

Satoews
Advocate
Advocate

Ah, thanks for clearing that up. 

Shawn T
0 Likes