TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Hrishikesh on July 10, 2017, 03:37:01 AM

Title: Need a Lisp routine to on/off particular layer list
Post by: Hrishikesh on July 10, 2017, 03:37:01 AM
Hi All,
I need a  Lisp routine to on/off particular layer list.
e.g. layers "0" "Defpoints" "Dim" "Text" "Embeds" should turn off/on in single command.

Thanks,
Hrishikesh
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: ziele_o2k on July 10, 2017, 04:03:33 AM
Something like that:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:laysoff ( / LayLst)
  2.   (setq LayLst (list "0" "Defpoints" "Dim" "Text" "Embeds"))
  3.   (vlax-for % (cd:ACX_Layers)
  4.     (if (member (vla-get-name %) LayLst)
  5.       (vla-put-layeron % :vlax-false)
  6.     )
  7.   )
  8.   (princ)
  9. )
  10. (defun c:layson ( / LayLst)
  11.   (setq LayLst (list "0" "Defpoints" "Dim" "Text" "Embeds"))
  12.   (vlax-for % (cd:ACX_Layers)
  13.     (if (member (vla-get-name %) LayLst)
  14.       (vla-put-layeron % :vlax-true)
  15.     )
  16.   )
  17.   (princ)
  18. )
  19. (defun cd:ACX_ADoc ()
  20.   (or
  21.     *cd-ActiveDocument*
  22.     (setq *cd-ActiveDocument*
  23.     )
  24.   )
  25.   *cd-ActiveDocument*
  26. )
  27. (defun cd:ACX_Layers ()
  28.   (or
  29.     *cd-Layers*
  30.     (setq *cd-Layers* (vla-get-Layers (cd:ACX_ADoc)))
  31.   )
  32.   *cd-Layers*
  33. )
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: Hrishikesh on July 10, 2017, 04:34:38 AM
Thanks, I will try this...
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: V-Man on July 10, 2017, 10:29:06 AM

Layer states will do this.
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: tive29 on July 10, 2017, 08:36:41 PM
Can you make it work with wildcards?

Tried this but did not work

Code: [Select]
(setq LayLst (list "*Dim*" "*Text" ))
Something like that:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:laysoff ( / LayLst)
  2.   (setq LayLst (list "0" "Defpoints" "Dim" "Text" "Embeds"))
  3.   (vlax-for % (cd:ACX_Layers)
  4.     (if (member (vla-get-name %) LayLst)
  5.       (vla-put-layeron % :vlax-false)
  6.     )
  7.   )
  8.   (princ)
  9. )
  10. (defun c:layson ( / LayLst)
  11.   (setq LayLst (list "0" "Defpoints" "Dim" "Text" "Embeds"))
  12.   (vlax-for % (cd:ACX_Layers)
  13.     (if (member (vla-get-name %) LayLst)
  14.       (vla-put-layeron % :vlax-true)
  15.     )
  16.   )
  17.   (princ)
  18. )
  19. (defun cd:ACX_ADoc ()
  20.   (or
  21.     *cd-ActiveDocument*
  22.     (setq *cd-ActiveDocument*
  23.     )
  24.   )
  25.   *cd-ActiveDocument*
  26. )
  27. (defun cd:ACX_Layers ()
  28.   (or
  29.     *cd-Layers*
  30.     (setq *cd-Layers* (vla-get-Layers (cd:ACX_ADoc)))
  31.   )
  32.   *cd-Layers*
  33. )
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: ronjonp on July 10, 2017, 10:28:14 PM
Replace: (member (vla-get-name %) LayLst) with (wcmatch (strcase (vla-get-name %)) "*DIM*,*TEXT")
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: Hrishikesh on July 11, 2017, 03:23:48 AM
Wow! This works great!!!
Thanks guys,
Both of you are made my work so easy & fast.

Thanks,
-Hrishikesh
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: ziele_o2k on July 11, 2017, 05:48:23 AM
Can you make it work with wildcards?

Tried this but did not work

Try with this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:laysoff ( / LayLst)
  2.   (setq LayLst (list "*Dim*" "*Text" ))
  3.   (vlax-for % (cd:ACX_Layers)
  4.     (if (wcmatch (strcase (vla-get-name %)) (strcase (cd:STR_ReParse LayLst ",")))
  5.       (vla-put-layeron % :vlax-false)
  6.     )
  7.   )
  8.   (princ)
  9. )
  10. (defun c:layson ( / LayLst)
  11.   (setq LayLst (list "*Dim*" "*Text" ))
  12.   (vlax-for % (cd:ACX_Layers)
  13.     (if (wcmatch (strcase (vla-get-name %)) (strcase (cd:STR_ReParse LayLst ",")))
  14.       (vla-put-layeron % :vlax-true)
  15.     )
  16.   )
  17.   (princ)
  18. )
  19. (defun cd:ACX_ADoc ()
  20.   (or
  21.     *cd-ActiveDocument*
  22.     (setq *cd-ActiveDocument*
  23.     )
  24.   )
  25.   *cd-ActiveDocument*
  26. )
  27. (defun cd:ACX_Layers ()
  28.   (or
  29.     *cd-Layers*
  30.     (setq *cd-Layers* (vla-get-Layers (cd:ACX_ADoc)))
  31.   )
  32.   *cd-Layers*
  33. )
  34. (defun cd:STR_ReParse (Lst Sep / res)
  35.   (setq res (car Lst))
  36.   (foreach % (cdr Lst)
  37.     (setq res (strcat res Sep %))
  38.   )
  39.   res
  40. )
Title: Re: Need a Lisp routine to on/off particular layer list
Post by: tive29 on July 16, 2017, 08:45:16 PM
Thanks. Both method works.