Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
tony
Posts: 62
Registered: ‎02-08-2011
Message 1 of 22 (703 Views)

Layers

703 Views, 21 Replies
03-24-2013 04:25 AM

I used to use a program called Strucad and if I had say 5 layers turned of from my batch of say 20 layers, there was a command that allowed you turn on a certain layer by choosing one of the 5 off layers. Strucad would present a window, only showing the layers that I had turned of

Is there something around to allow me to do this in Autocad 3013

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 2 of 22 (702 Views)

Re: Layers

03-24-2013 04:27 AM in reply to: tony

Hi,

 

start the AutoCAD layermanager, then sort by frozen layer or layers switched off, then you have all on top of your list.

Another option is to create a layerfilter just showing the ones that are frozen or off.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 3 of 22 (692 Views)

Re: Layers

03-24-2013 04:52 AM in reply to: Alfred.NESWADBA

tony wrote:

...

Is there something around to allow me to do this in Autocad 3013

 

Off topic

Good morning, Alfred

We're getting too old!!! Already able to respond to questions about AutoCAD 3013...

I know that was a typo, but it was an excuse to say...

Good day to all

 

Cheers

Henrique

Valued Contributor
tony
Posts: 62
Registered: ‎02-08-2011
Message 4 of 22 (660 Views)

Re: Layers

03-24-2013 04:38 PM in reply to: tony

Thanks for the replies. I was hoping to get something like a lisp routine that would present a window just showing the off layers and allowing me to select the layer I want on. Its about making it quick by not hasving to open the layer manager as I find this a bit cumbersome.

 

Regards

 

Tony

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 5 of 22 (651 Views)

Re: Layers

03-24-2013 08:10 PM in reply to: tony

tony wrote:

I used to use a program called Strucad and if I had say 5 layers turned of from my batch of say 20 layers, there was a command that allowed you turn on a certain layer by choosing one of the 5 off layers. Strucad would present a window, only showing the layers that I had turned of

Is there something around to allow me to do this in Autocad 3013


Can you give use a rundown on how that works?

 

*Expert Elite*
3wood
Posts: 968
Registered: ‎03-25-2009
Message 6 of 22 (623 Views)

Re: Layers

03-26-2013 03:38 PM in reply to: tony

You can try command LPO in attached LAYER.vlx, which can turn on all layers temporarily and allow you to pick up some objects, then retrieve previous layer status but turn on the layers of the objects selected.

 

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 7 of 22 (591 Views)

Re: Layers

03-27-2013 08:39 AM in reply to: tony

Tony, please try this.

; Turn ON selected layers
; Stefan M. - 27.03.2013
(defun C:LAYER_ON ( / *error* acDoc filen filew id l layers)
  (vl-load-com)
  (or acDoc (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-startundomark acDoc)

  (defun *error* (m)
    (and
      m
      (not (wcmatch (strcase m) "*CANCEL*,*QUIT*"))
      (princ (strcat "\nError: " m))
      )
    (vla-endundomark acDoc)
    )

  (vlax-for la (setq layers (vla-get-layers acDoc))
    (if
      (eq (vla-get-LayerOn la) :vlax-false)
       (setq l (cons (vla-get-Name la) l))
       )
    )
  (if l 
    (progn
      (setq l (acad_strlsort l))
      (setq filew (open (setq filen (strcat (getvar 'dwgprefix) "temp_layer_dialog.dcl")) "w"))
      (write-line
        "layer_on_dialog : dialog {
       label = \"SELECT LAYERS TO TURN ON\";
       : column {"
        filew
        )
      (mapcar
        (function
          (lambda (a)
            (write-line
              (strcat ":toggle {label = \"" a "\"; key = \"" a "\";}")
              filew
              )
            )
          )
        l
        )
      (write-line "} ok_cancel;}" filew)
      (close filew)
      (if
        (>= (setq id (load_dialog filen)) 0)
         (if
           (new_dialog "layer_on_dialog" id)
            (progn
              (mapcar
                (function
                  (lambda (a)
                    (action_tile a
                                 (strcat "(vla-put-LayerOn (vla-item layers \""
                                         a
                                         "\") (nth (atoi $value) (list :vlax-false :vlax-true)))"
                                         )
                                 )
                    )
                  )
                l
                )
              (start_dialog)
              (unload_dialog id)
              )
            (princ "\nWrong dialog definition")
            )
         (princ "\nDCL file not found")
         )
      )
    (princ "\nAll layers are ON")
    )
  (*error* nil)
  (princ)
  )

 

Valued Contributor
tony
Posts: 62
Registered: ‎02-08-2011
Message 8 of 22 (574 Views)

Re: Layers

03-27-2013 04:46 PM in reply to: phanaem
Thank you very much for that. It works perfectly. I hope I'm not being too cheeky here buy is it possible to not show layers beginning with X. As I have about 20 layers beginning with X that are mostly turned off, so they are always showing in the list of off layers. Regards Tony Gibbs 0408408200 64654141 __________ Information from ESET Smart Security, version of virus signature database 8169 (20130327) __________ The message was checked by ESET Smart Security. http://www.eset.com
Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 9 of 22 (561 Views)

Re: Layers

03-28-2013 12:06 AM in reply to: tony

Hi Tony

This version ignores layers start with "X".

I found a bug in previous one related to Xrefs layers name, so those layers are also ignored.

; Turn ON selected layers
; Stefan M. - 28.03.2013
(defun C:LAYER_ON ( / *error* acDoc filen filew id l layers)
  (vl-load-com)
  (or acDoc (setq acDoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-startundomark acDoc)

  (defun *error* (m)
    (and
      m
      (not (wcmatch (strcase m) "*CANCEL*,*QUIT*"))
      (princ (strcat "\nError: " m))
      )
    (vla-endundomark acDoc)
    )

  (vlax-for la (setq layers (vla-get-layers acDoc))
    (if
      (eq (vla-get-LayerOn la) :vlax-false)
      (if
        (not (wcmatch (strcase (setq n (vla-get-Name la))) "X*,*|*"))
        (setq l (cons n l))
      )
    )
  )
  (if l 
    (progn
      (setq l (acad_strlsort l))
      (setq filew (open (setq filen (strcat (getvar 'dwgprefix) "temp_layer_dialog.dcl")) "w"))
      (write-line
        "layer_on_dialog : dialog {
       label = \"SELECT LAYERS TO TURN ON\";
       : column {"
        filew
        )
      (mapcar
        (function
          (lambda (a)
            (write-line
              (strcat ":toggle {label = \"" a "\"; key = \"" a "\";}")
              filew
              )
            )
          )
        l
        )
      (write-line "} ok_cancel;}" filew)
      (close filew)
      (if
        (>= (setq id (load_dialog filen)) 0)
         (if
           (new_dialog "layer_on_dialog" id)
            (progn
              (mapcar
                (function
                  (lambda (a)
                    (action_tile a
                                 (strcat "(vla-put-LayerOn (vla-item layers \""
                                         a
                                         "\") (nth (atoi $value) (list :vlax-false :vlax-true)))"
                                         )
                                 )
                    )
                  )
                l
                )
              (start_dialog)
              (unload_dialog id)
              )
            (princ "\nWrong dialog definition")
            )
         (princ "\nDCL file not found")
         )
      (if (findfile filen) (vl-file-delete filen))
      )
    (princ "\nAll layers are ON")
    )
  (*error* nil)
  (princ)
  )

 

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 10 of 22 (549 Views)

Re: Layers

03-28-2013 04:22 AM in reply to: tony

If you have DosLib instaled, the code can be reduced significantly.

(defun C:LAYER_ON ( / *error* acDoc filen filew id l layers r)
  (vl-load-com)
  (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark acDoc)

  (defun *error* (m)
    (and
      m
      (not (wcmatch (strcase m) "*CANCEL*,*QUIT*"))
      (princ (strcat "\nError: " m))
      )
    (vla-endundomark acDoc)
    )

  (vlax-for la (setq layers (vla-get-layers acDoc))
    (if
      (eq (vla-get-LayerOn la) :vlax-false)
      (if
        (not (wcmatch (strcase (setq n (vla-get-Name la))) "X*,*|*"))
        (setq l (cons n l))
      )
    )
  )
  (if l 
    (foreach x (dos_multilist "Select layers" "Layer list" l)
      (vla-put-LayerOn (vla-item layers x) :vlax-true)
      )
    (princ "\nAll layers are ON")
    )
  (*error* nil)
  (princ)
  )

 Or even

(defun C:LAYER_ON ( / layers)
  (setq layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
  (foreach x (dos_layerlistbox "Select Layers" "layer list" 385)
      (vla-put-LayerOn (vla-item layers x) :vlax-true)
  )
  (princ)
)

 However, in the last one you can not filter out layers name starting with "X".

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community