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

0 Members and 1 Guest are viewing this topic.

Hrishikesh

  • Newt
  • Posts: 35
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: 39
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

  • Newt
  • Posts: 35
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: 332
  • I exist therefore I am!
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 2010 64-bit, AutoCADMap 2008, 2010, Revit 2012

tive29

  • Mosquito
  • Posts: 20
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: 6312
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 10 x64 - AutoCAD /C3D 2018

Custom Build PC

Hrishikesh

  • Newt
  • Posts: 35
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: 39
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

  • Mosquito
  • Posts: 20
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.