Author Topic: Not thinking clearly here with COND statement...  (Read 764 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Not thinking clearly here with COND statement...
« on: April 17, 2023, 06:12:34 PM »
I check for the subjectcode value "03". If the value isn't a match, do the first set of commands. If the value is a match do the second set of commands.


Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  2.   (setq attvalue (LM:GetAttributeValue (ssname ss 0) "SUBJECTCODE"))
  3.  
  4.   (cond
  5.    ((wcmatch (strcase attvalue)
  6.               "03"
  7.    
  8.      (command "clayout" "Model")
  9.      (command "-layer" "unlock" "TTBK_BORD_LINES" "")
  10.      (command "erase" "all" "")
  11.      (command "_.-purge" "_D" "decimal,fraction" "N")
  12.      (command "-layer" "lock" "TTBK_BORD_LINES" "")
  13.      (command "Zoom" "all")
  14.      (command "_.-insert" "STA_STR_STANDARDS" "0,0" dim dim "0")
  15.      (command "Clayout" "ANSI-D 22x34")
  16.      (command "-layer" "filter" "s" "All" "")
  17.   )
  18.    )
  19.   ((wcmatch (strcase attvalue)
  20.               "03"
  21.    
  22.      (command "clayout" "ANSI-D 22x34")
  23.      (command "-layer" "unlock" "TTBK_BORD_LINES" "")
  24.      (command "erase" "all" "")
  25.      (command "_.-purge" "_D" "Annotative,DIMEN" "N")
  26.      (command "-layer" "lock" "TTBK_BORD_LINES" "")
  27.      (command "Zoom" "all")
  28.      (command "Clayout" "MODEL")
  29.    )
  30.   )
  31.   )

I used this as my guide http://www.theswamp.org/index.php?topic=13046.msg158557#msg158557.

Code - Auto/Visual Lisp: [Select]
  1.   ((= 1 0)
  2.     none of this will get executed
  3.     because the conditions is false
  4.   ) ; end cond 1
  5.  
  6.   ((= 1 1)
  7.      do all of this because it is true
  8.      and this
  9.      and this
  10.    ) ; end cond 2
  11.  
  12.    ((= 2 2)
  13.      none of this will get
  14.      executed even if it is true
  15.      because the prior stmt was true
  16.    ) ; end cond 3
  17.  
  18.    (T
  19.      This is often placed at the last position
  20.      in a condition statement and will be executed
  21.      if all the prior conditions are false
  22.      if any one of the above conditions are true
  23.       this will not be executed
  24.    ) ; end cond 4
  25. ) ; end cond stmt

Which means I'm not understanding something. If my value is 03, the first set of commands would run. If the value is 20, the first set of commands doesn't run and Moves on to cond 2 and runs.

What I have is a title block in both paper space and model space for two different disciplines. The user fills out a card in a 3rd party program where the subject code gets generated and filled out in both the MS and the PS title blocks. Upon start-up I want this code to check for subject code and eliminate the title block that doesn't match the subject code for the corresponding space. The example above, "03" subject code is for a PS title block. Subject Code 20 would be for a MS title block. Mind you, there are probably 50 various subject codes between the two disciplines.

I haven't provided Lee Mac's LM:GetAttributeValue routine that is part of the attvalue variable.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Not thinking clearly here with COND statement...
« Reply #1 on: April 17, 2023, 07:10:46 PM »
A few things straight off the bat -

1. Your test expressions are each missing a closing parenthesis for the wcmatch expression:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (strcase attvalue) "03"

2. Both of your test expressions are the same, and so the second condition will never be executed (as, if the test expression is validated, cond will stop evaluation at the first condition; if the test expression is not validated, neither conditions will be evaluated).

3. If "03" is within the string being tested, you may need to add wildcard operators [e.g. (wcmatch (strcase attvalue) "*03*")], otherwise, if you're testing for an exact match, I feel that a simple equality operator is more appropriate, e.g. (= (strcase attvalue) "03")

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Not thinking clearly here with COND statement...
« Reply #2 on: April 17, 2023, 07:11:17 PM »
Why are you looking for a code? It seems as if you just want to know what's in model or paperspace?

Here's a direct way to select them.
Code - Auto/Visual Lisp: [Select]
  1. ;; In modelspace
  2. (setq ss (ssget "_x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1) (410 . "Model"))))
  3. ;; In paperspace
  4. (setq ss (ssget "_x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1) (410 . "ANSI-D 22x34"))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: Not thinking clearly here with COND statement...
« Reply #3 on: April 18, 2023, 11:26:22 AM »
A few things straight off the bat -

1. Your test expressions are each missing a closing parenthesis for the wcmatch expression:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (strcase attvalue) "03"

Thanks for pointing that out.

2. Both of your test expressions are the same, and so the second condition will never be executed (as, if the test expression is validated, cond will stop evaluation at the first condition; if the test expression is not validated, neither conditions will be evaluated).

I think this was the crux of my question. I didn't change the second test expression because I didn't understand if I needed to test for the thing within the cond.

3. If "03" is within the string being tested, you may need to add wildcard operators [e.g. (wcmatch (strcase attvalue) "*03*")], otherwise, if you're testing for an exact match, I feel that a simple equality operator is more appropriate, e.g. (= (strcase attvalue) "03")

It will be an exact match. The list is very specific.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 327
Re: Not thinking clearly here with COND statement...
« Reply #4 on: April 18, 2023, 11:27:25 AM »
Why are you looking for a code? It seems as if you just want to know what's in model or paperspace?

Here's a direct way to select them.
Code - Auto/Visual Lisp: [Select]
  1. ;; In modelspace
  2. (setq ss (ssget "_x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1) (410 . "Model"))))
  3. ;; In paperspace
  4. (setq ss (ssget "_x" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1) (410 . "ANSI-D 22x34"))))

I definitely could have gone farther, if my brain went that far. Thanks for that.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Not thinking clearly here with COND statement...
« Reply #5 on: April 18, 2023, 11:30:37 AM »
You could also check the space within a loop like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  2.   (foreach e (mapcar 'cadr (ssnamex s))
  3.     (if (= "Model" (cdr (assoc 410 (entget e))))
  4.         ;; Do modelspace stuff
  5.         ;; Else do paperspace stuff
  6.     )
  7.   )
  8. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC