Need help with IF AND OR statement

Need help with IF AND OR statement

Anonymous
Not applicable
745 Views
3 Replies
Message 1 of 4

Need help with IF AND OR statement

Anonymous
Not applicable

I have tried to do this in multiple ways, but what i am trying to do is test if the first line is true with a combination of an AND , OR condition & if not run the code on the next line. Originally i was trying to do this with just an IF statement, but i later added in the cond statement to see if that would work. Whichever way i write it either only does the top line or it does both lines. i cant get it to run the second line if the top line is false. Here is the code in question & i have also uploaded the whole file. ln13 is a variable for the state that the project is in based on a dialog box selection that gets created with another lisp routine. ln6 is a variable for the city the project is in. Basically, if the project is  in MANHATTAN, BRONX, BROOKLYN, FLUSHING, JACKSON HEIGHTS, QUEENS, NEW YORK, or STATEN ISLAND i want to execute:

 

(Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNYC.dwg" "0,0" "1" "" "")

 

If the project is in NY , but not in those cities i want it to execute:

 

(Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNY.dwg" "0,0" "1" "" "")

 

code snippet is here:

 

(cond
(If (AND (= ln13 "NY")(OR (= (strcase ln6 "MANHATTAN"))(= (strcase ln6 "BRONX"))(= (strcase ln6 "BROOKLYN"))(= (strcase ln6 "FLUSHING"))(= (strcase ln6 "JACKSON HEIGHTS"))(= (strcase ln6 "QUEENS"))(= (strcase ln6 "NEW YORK"))(= (strcase ln6 "STATEN ISLAND")))))(Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNYC.dwg" "0,0" "1" "" "")
(Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNY.dwg" "0,0" "1" "" "")

)

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

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous ,

 

Good lord that's a huge lisp file lol. Is that the one we tried working on previously? If you are unsure what I'm referring to then nevermind.

 

Anyways, there are a couple ways to accomplish this. Here's the first, it is how you were trying to originally accomplish it:

 

 

(cond
  ((and (= ln13 "NY")
        (or (= (strcase ln6) "MANHATTAN")
            (= (strcase ln6) "BRONX")
            (= (strcase ln6) "BROOKLYN")
            (= (strcase ln6) "FLUSHING")
            (= (strcase ln6) "JACKSON HEIGHTS")
            (= (strcase ln6) "QUEENS")
            (= (strcase ln6) "NEW YORK")
            (= (strcase ln6) "STATEN ISLAND")))
    (Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNYC.dwg" "0,0" "1" "" "")
  );cond 1
  (t
    (Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNY.dwg" "0,0" "1" "" "")
  );cond else
);cond

 

 

 

...but let's keep in mind that coding can be an art sometimes and we might like to be more efficient. We can see that our '(strcase ln6)' is repeated multiple times. This should hint to us that there HAS to be a better way, right?

Well, AutoLISP LOVES lists.. so let's instead create a list of all the places in our OR statement, and just check if our text is a member of it or not:

 

 

(cond
  ((and (= ln13 "NY")
        (member (strcase ln6) '("MANHATTAN" "BRONX" "BROOKLYN" "FLUSHING" "JACKSON HEIGHTS" "QUEENS" "NEW YORK" "STATEN ISLAND")))
    (Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNYC.dwg" "0,0" "1" "" "")
  );cond 1
  (t
    (Command "-layer" "s" "A-ANNO-TEXT" "" "insert" "H:\\Overlays\\BCK_McDonalds\\CoverinfoNY.dwg" "0,0" "1" "" "")
  );cond else
);cond

 

 

Hope this helps! Best,

~DD

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks. I will try that

0 Likes
Message 4 of 4

Anonymous
Not applicable

This is embarrassing, but it was supposed to be ln7 & not ln6. Also i took out the strcase keyword because i thought that was causing the problem. i was trying to guard against someone filling in the city name with all capital letters, but maybe i dont need that.It does work now so thank you