TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on July 02, 2021, 12:17:10 PM

Title: If statement is wrong ?
Post by: jlogan02 on July 02, 2021, 12:17:10 PM
I have to find text objects on these layers and in the specified crossing window area. There are times though when there won't be anything in that area. The layers will always exist.

My routine bombs when the text objects don't exist.


Code - Auto/Visual Lisp: [Select]
  1.  (if (= (tblsearch "Layer" "TEXT2,TBLK_TBLK_REVTEXT"))
  2.      (setq rev1 (ssget "c"
  3.         '(31.75 21.75)
  4.         '(31.6875 5.25)
  5.         '((8 . "TEXT2,TBLK_TBLK_REVTEXT"))
  6.                 )
  7.           )
  8.   (command "._change" rev1 "" "p" "la" "TBLK_TBLK_REVINIT" "")
  9.  
  10. )

Have I been misunderstanding (if ???

I think my code is saying...

If the layers exist....
do this
and if they don't exist, carry on.
Title: Re: If statement is wrong ?
Post by: JohnK on July 02, 2021, 12:29:24 PM
TABLESEARCH will return nil if no entry is found but my immediate question is what is the EQUAL function checking against (for)?

Code - Auto/Visual Lisp: [Select]
  1. (if (= (tblsearch "Layer" "TEXT2,TBLK_TBLK_REVTEXT"))
Title: Re: If statement is wrong ?
Post by: jlogan02 on July 02, 2021, 01:00:24 PM
Yeah, I forgot to erase that before I posted it. I was doing some stab in the dark crap.
Title: Re: If statement is wrong ?
Post by: JohnK on July 02, 2021, 01:44:13 PM
Ah. got it. Well, I'm very fuzzy on my lisp knowledge so let me tackle some of the higher level stuff and we'll see if you can't get this figured out.

1. I don't think you can use tablesearch to search for two layers like that. You may just have to search each layer one at a time.
2. Your IF statement is formatted incorrectly.

The proper format is:
Code - Auto/Visual Lisp: [Select]
  1. (if testexpr
  2.     thenexpr
  3.     [elseexpr]
  4.     )

so if you take a look at your structure, you'll see that the THENEXPR is just a simple SETQ and the optional ELSEEXPR is a command call. If you need to group those two statements (SETQ and COMMAND) into one expression you can use PROGN

Code - Auto/Visual Lisp: [Select]
  1. (if testexpr
  2.     (progn
  3.        thenexpr
  4.        subsiquent thenexpr
  5.      )
  6.     [elseexpr]
  7.     )

But keep in mind as your structuring your expressions not to fall into the trap of sloppy structure (akin to sloppy drafting) because often times when you have more TESTEXPRs that need to be met, a cleaner method is to use COND.

Code - Auto/Visual Lisp: [Select]
  1.   ((testexpr)
  2.     result
  3.    )
  4.   ((testexpr)
  5.     result
  6.    )
  7.   ...
  8. )

So, clean up that and we'll see if I can't do a crash course on SSGET.
Title: Re: If statement is wrong ?
Post by: ronjonp on July 02, 2021, 03:35:38 PM
I have to find text objects on these layers and in the specified crossing window area. There are times though when there won't be anything in that area. The layers will always exist.

My routine bombs when the text objects don't exist.


Code - Auto/Visual Lisp: [Select]
  1.  (if (= (tblsearch "Layer" "TEXT2,TBLK_TBLK_REVTEXT"))
  2.      (setq rev1 (ssget "c"
  3.         '(31.75 21.75)
  4.         '(31.6875 5.25)
  5.         '((8 . "TEXT2,TBLK_TBLK_REVTEXT"))
  6.                 )
  7.           )
  8.   (command "._change" rev1 "" "p" "la" "TBLK_TBLK_REVINIT" "")
  9.  
  10. )

Have I been misunderstanding (if ???

I think my code is saying...

If the layers exist....
do this
and if they don't exist, carry on.
Just check that you have a selection:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq rev1 (ssget "_C" '(31.75 21.75) '(31.6875 5.25) '((8 . "TEXT2,TBLK_TBLK_REVTEXT"))))
  2.   (command "._change" rev1 "" "p" "la" "TBLK_TBLK_REVINIT" "")
  3. )
And you cannot pass multiple layers to tblsearch.
Title: Re: If statement is wrong ?
Post by: JohnK on July 02, 2021, 04:28:11 PM
Oh, well I was moving at a bit slower pace but that works too (I got pulled away in two different directions anyways). Thanks, ronjonp
Title: Re: If statement is wrong ?
Post by: ronjonp on July 02, 2021, 11:45:55 PM
Oh, well I was moving at a bit slower pace but that works too (I got pulled away in two different directions anyways). Thanks, ronjonp
*cheers*