Author Topic: Testing for multiple conditions  (Read 1956 times)

0 Members and 1 Guest are viewing this topic.

jbuzbee

  • Swamp Rat
  • Posts: 851
Testing for multiple conditions
« on: September 10, 2014, 04:08:26 PM »
I'm having major mental blockage this afternoon.  I want to test for several condition with a layer and then add it to a list if it meets all the conditions.  I know the following isn't right but maybe it can spark some ideas:

Code: [Select]
(vlax-for i(vla-get-layers(vla-get-ActiveDocument(vlax-get-acad-object)))
  (cond((not(vl-string-search "|" (vla-get-name i)))
((=(vla-get-layeron i):vlax-true))
((=(vla-get-freeze i):vlax-false))
((setq llist(append llist (vla-get-name i))))
)
       )
  )

Thanks for any input!!

jb
James Buzbee
Windows 8

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Testing for multiple conditions
« Reply #1 on: September 10, 2014, 04:20:41 PM »
Perhaps:
Code - Auto/Visual Lisp: [Select]
  1.        (= (vla-get-layeron i) :vlax-true)
  2.        (= (vla-get-freeze i) :vlax-false)
  3.        (setq llist (cons (vla-get-name i) llist))
  4.   )
  5. ;;;  (cond ((not (vl-string-search "|" (vla-get-name i)))
  6. ;;;         ((= (vla-get-layeron i) :vlax-true))
  7. ;;;         ((= (vla-get-freeze i) :vlax-false))
  8. ;;;         ((setq llist (append llist (vla-get-name i))))
  9. ;;;        )
  10. ;;;  )
  11. )
« Last Edit: September 10, 2014, 04:26:38 PM by CAB »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: Testing for multiple conditions
« Reply #2 on: September 10, 2014, 04:21:00 PM »
I'm having major mental blockage this afternoon.  I want to test for several condition with a layer and then add it to a list if it meets all the conditions.  I know the following isn't right but maybe it can spark some ideas:

Code: [Select]
(vlax-for i(vla-get-layers(vla-get-ActiveDocument(vlax-get-acad-object)))
  (cond((not(vl-string-search "|" (vla-get-name i)))
((=(vla-get-layeron i):vlax-true))
((=(vla-get-freeze i):vlax-false))
((setq llist(append llist (vla-get-name i))))
)
       )
  )

Thanks for any input!!

Code - Auto/Visual Lisp: [Select]
  1. (defun _GetUsedLayers ( / layerName)
  2.                 (vla-get-ActiveDocument (vlax-get-acad-object))
  3.               )
  4.     (if
  5.       (and
  6.         (not (vl-string-search "|" (setq layerName (vla-get-name i))))
  7.         (= (vla-get-layeron i) :vlax-true)
  8.         (= (vla-get-freeze i) :vlax-false)
  9.       )
  10.        (setq layers (cons layerName layers))
  11.     )
  12.   )
  13.   (reverse layers)
  14. )
  15.  

[Edit] - Ninja wins.  :-D
"How we think determines what we do, and what we do determines what we get."

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Testing for multiple conditions
« Reply #3 on: September 10, 2014, 04:28:32 PM »
Thanks RonjonP - that did it!
James Buzbee
Windows 8

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Testing for multiple conditions
« Reply #4 on: September 10, 2014, 05:27:52 PM »
The (not (vl-string-search ... )) could also be replaced with a single wcmatch test, e.g.:

Code - Auto/Visual Lisp: [Select]
  1.     (if (and (wcmatch (vla-get-name i) "~*|*")
  2.              (= :vlax-true (vla-get-layeron i))
  3.              (= :vlax-false (vla-get-freeze i))
  4.         )
  5.         (setq llist (cons (vla-get-name i) llist))
  6.     )
  7. )

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Testing for multiple conditions
« Reply #5 on: September 11, 2014, 09:10:54 AM »
Thanks RonjonP - that did it!
Glad to help out  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC