Hide all but the current layer

Hide all but the current layer

saitoib
Advocate Advocate
11,303 Views
8 Replies
Message 1 of 9

Hide all but the current layer

saitoib
Advocate
Advocate

Hi all.

 

I would like to hide all layers except the current layer.

Is the only way to do this in lisp is to use vla-get-layers and vla-get-count to hide all layers individually?

Also, after the process is finished, I need to restore all the layers to their original state.
Is it still the same procedure to switch them back to visible?
 
thank you.
Saitoib
0 Likes
Accepted solutions (2)
11,304 Views
8 Replies
Replies (8)
Message 2 of 9

john.uhden
Mentor
Mentor

@saitoib 

Since you can't freeze the current layer using the -layer command, you can just...

-layer _F *

To get them back to where they all were, I suggest you use Layer Manager before you freeze *.

I think that most users use OFF for temporary purposes, and when done with their contrivances they just turn them all back ON, none of which affects their freeze/thaw states.  BUT you CAN turn OFF the current layer, so be careful.

John F. Uhden

Message 3 of 9

Sea-Haven
Mentor
Mentor

Why not use Layiso that is what that function is for.

Message 4 of 9

hak_vz
Advisor
Advisor
Accepted solution

Here you have it with some bonus functions that I use.

 

(setq layer_ON_OFF_list '("Layer1" "Layer2" "Layer3"))
;create DCL selection for initializing global variable

(defun Table (s / d r)
	(while (setq d (tblnext s (null d)))
		(setq r (cons (cdr (assoc 2 d)) r))
	)
)

;Hides all layers that are stored in layer_ON_OFF_list
(defun C:LOFF (/ layobj)
  (foreach layname layer_ON_OFF_list  ; add as many as you like
    (if (setq layobj (tblobjname "layer" layname))
       (vla-put-LayerOn (vlax-ename->vla-object layobj) 0)
    )
  )
  (princ)
)

;Shows all layers that were hidden (stored in layer_ON_OFF_list)
(defun C:LON (/ layobj)
  (foreach layname layer_ON_OFF_list  ; add as many as you like
    (if (setq layobj (tblobjname "layer" layname))
       (vla-put-LayerOn (vlax-ename->vla-object layobj) 1)
    )
  )
  (princ)
)

;hide all but current layer
(defun c:habc ()
	(foreach layobj (Table "layer")
		(if (/= layobj (getvar 'clayer))
			(vla-put-LayerOn (vlax-ename->vla-object (tblobjname "layer" layobj)) 0)
		)
	)
	(princ)
)

 

 

Create  yourself function that turns on all layer based on this code.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant

I can only recommend using Kent's Layer Isolation routine that I use daily for more than a decade.

I'll share my little modified version, differences are described lower.

 

 

;; Added Lock/unlock Isolation [command name: LIL, LUO-same command for both]
;; Added Isolation of current layer if nothing selected before (PICKFIRST=1)
;; Changed behavior when current layer is turning off. Now a layer of the first selected object is made current.
;; Beekeeper, January 2013

 

;; LayerIsolateOnOff.lsp [command names: LIO, LUO]
;; To Isolate and Unisolate only the On-Off condition of Layers of selected objects.
;; LIO isolates Layers of selected objects, leaving those Layers on and turning all
;; other Layers off that are not already off. If repeated before LUO turns those
;; Layers back on, makes further isolations, to as many levels as desired.
;; LUO turns latest set of turned-off Layers back on, without undoing other Layer
;; options that may have been used under isolated conditions [as happens with
;; some (e.g. colors) if using AutoCAD's standard LAYERUNISO to return to un-
;; isolated conditions after using LAYISO]. When repeated, steps back through
;; as many isolations as were done with LIO [LAYISO can only step back once].
;; Kent Cooper, August 2011

Message 6 of 9

saitoib
Advocate
Advocate

Thank you all for your guidance!

I have received a lot of guidance and I need some time to understand it.

Saitoib
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

 


@saitoib wrote:

.... I would like to hide all layers except the current layer. .... after the process is finished, I need to restore all the layers to their original state. ....


@ВeekeeCZ , thanks for the reference, but [the original] LIO requires picking something(s).  Your modification to isolate the current Layer appears to require that when you want to isolate the Layers of selected things, it is necessary to select them first, unlike virtually any other command, so I don't think I'd go for that approach -- I'd be sure to sometimes put in the command name without pre-selection as I can for other commands, and then the ones I wanted to isolate wouldn't be visible to select [unless the current Layer was one of them].

 

How about just this?

 

(defun C:LOABC () ; = Layers Off All But Current

  (command "_.layer" "_off" "*" "_no" "")

  (princ)

)

 

Then, a plain old LAYERP command will restore the previous conditions.

 

[That assumes you haven't upped the setting of the EXPERT System Variable to 1 or more.  If you have, and that is your standard setting, omit the "_no".]

Kent Cooper, AIA
0 Likes
Message 8 of 9

saitoib
Advocate
Advocate

@Sea-Haven 

The LAYISO command was new to me.
However, I could not get the desired result with isolation.
 
Thank you for your valuable functions.
Especially, the tblnext command is very useful!
 
Sorry, I didn't understand all of it, it was too long!
 
I didn't realize that the original layer command alone can be used for this purpose!
 
Thank you all very much!
 
Saitoib
0 Likes
Message 9 of 9

calderg1000
Mentor
Mentor

Regards @saitoib 

You don't need Lisp to do what you require, use ISOLATE...,Then you can restore it with UNISOLATE

 

calderg1000_0-1653606939943.png

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes