Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 22
Tony_Gibbs
1364 Views, 21 Replies

Layers

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

21 REPLIES 21
Message 2 of 22

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 22
hmsilva
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

EESignature

Message 4 of 22
Tony_Gibbs
in reply to: Tony_Gibbs

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

Message 5 of 22
pbejse
in reply to: Tony_Gibbs


@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?

 

Message 6 of 22
3wood
in reply to: Tony_Gibbs

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.

 

Message 7 of 22
phanaem
in reply to: Tony_Gibbs

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)
  )

 

Message 8 of 22
Tony_Gibbs
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
Message 9 of 22
phanaem
in reply to: Tony_Gibbs

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)
  )

 

Message 10 of 22
phanaem
in reply to: Tony_Gibbs

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".

 

Message 11 of 22
RocksterB
in reply to: phanaem

Ohhh! Can I get one of these for frozen layers? No need to filtering the X-layers.

Message 12 of 22
phanaem
in reply to: RocksterB


@randy.brockington wrote:

Ohhh! Can I get one of these for frozen layers? No need to filtering the X-layers.


The short, DosLib dependent version:

(defun C:thaw ( / layers)
  (setq layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
  (foreach x (dos_layerlistbox "Select Layers" "Layer list" 388)
      (vla-put-Freeze (vla-item layers x) :vlax-false)
  )
  (command "regen")
  (princ)
)

 To thaw all layers, use "_laythw" command.

Message 13 of 22
RocksterB
in reply to: phanaem

Since I don't have theDOSLIB.arx loading, I'll need the long one. Thanks in advance!

Message 14 of 22
Kent1Cooper
in reply to: Tony_Gibbs


@Tony wrote:

.... 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. ....


What would you think of something that would let the User select an object on the Layer they want turned on, rather than select the Layer name from a list of some kind?  I can sort of imagine how one might make a routine to turn on [and/or thaw] all Layers, and highlight all the objects on the Layers that were turned off [and/or frozen], so you can distinguish what's on those and pick something.  Presumably it could be made to allow multiple objects to turn on/thaw more than one such Layer at the same time.  Would that be a useful approach?

Kent Cooper, AIA
Message 15 of 22
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....

What would you think of something that would let the User select an object on the Layer they want turned on, rather than select the Layer name from a list of some kind? .... it could be made to allow multiple objects to turn on/thaw more than one such Layer at the same time. ....


Such as, for example, the attached LayerThawOnSelect.lsp, with its LTOS command.

Kent Cooper, AIA
Message 16 of 22
RocksterB
in reply to: Kent1Cooper

I'm not sure if this messge was for me, but I did find the routine helpful.

Message 17 of 22
Kent1Cooper
in reply to: RocksterB


@randy.brockington wrote:

I'm not sure if this messge was for me, but I did find the routine helpful.


Good -- it wasn't for anyone in particular, but just an approach to the operation that I thought might be preferable for some, to select drawn objects on Layers you want thawed and turned on, rather than selecting Layer names from a list or dialog box.

 

One interesting difference is that you don't even need to know the names of the Layer(s) involved -- you just need to recognize the elements drawn on the Layer(s) that you want thawed/on -- which could be an advantage if you have long and complicated Layer names that might require some careful looking to get the right ones on a list.

 

One possible drawback, however, is that there actually needs to be something drawn on the Layer(s) you want thawed/on.  You can't use it to thaw and turn on a Layer that has nothing drawn for you to pick on.

Kent Cooper, AIA
Message 18 of 22
phanaem
in reply to: Tony_Gibbs

After some tests, I decided to remove my last code.

I need some time to fix it

Message 19 of 22
RocksterB
in reply to: Kent1Cooper


@Kent1Cooper wrote:

One possible drawback, however, is that there actually needs to be something drawn on the Layer(s) you want thawed/on.  You can't use it to thaw and turn on a Layer that has nothing drawn for you to pick on.

The positive use of the routine outweighs the drawback.

Message 20 of 22
Nrhoads
in reply to: phanaem


@phanaem wrote:

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.

 

CODE WAS HERE 


Thank you for posting this command! Can you add a scrollbar or something similar to the dialogue box?  I'm getting an error "Dialog too large to fit on screen" when there are a lot of layers off.  The dialog box gets too long to fit on screen and AutoCad freaks out. I believe a scrollbar would fix that but I'm not a programmer, just a user 😉

 

I am hoping to be able use this and also make one for listing frozen layers to thaw, and one for no-plot layers to make plotable  as well... I HATE the Acad layer manager, if you didn't notice.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost