Author Topic: Need a Lisp routine to on/off particular layer list  (Read 3215 times)

0 Members and 1 Guest are viewing this topic.

Hrishikesh

  • Guest
Need a Lisp routine to on/off particular layer list
« 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

ziele_o2k

  • Newt
  • Posts: 49
Re: Need a Lisp routine to on/off particular layer list
« Reply #1 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. )

Hrishikesh

  • Guest
Re: Need a Lisp routine to on/off particular layer list
« Reply #2 on: July 10, 2017, 04:34:38 AM »
Thanks, I will try this...

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Need a Lisp routine to on/off particular layer list
« Reply #3 on: July 10, 2017, 10:29:06 AM »

Layer states will do this.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

tive29

  • Guest
Re: Need a Lisp routine to on/off particular layer list
« Reply #4 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. )

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Need a Lisp routine to on/off particular layer list
« Reply #5 on: July 10, 2017, 10:28:14 PM »
Replace: (member (vla-get-name %) LayLst) with (wcmatch (strcase (vla-get-name %)) "*DIM*,*TEXT")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Hrishikesh

  • Guest
Re: Need a Lisp routine to on/off particular layer list
« Reply #6 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

ziele_o2k

  • Newt
  • Posts: 49
Re: Need a Lisp routine to on/off particular layer list
« Reply #7 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. )

tive29

  • Guest
Re: Need a Lisp routine to on/off particular layer list
« Reply #8 on: July 16, 2017, 08:45:16 PM »
Thanks. Both method works.