Turn ON 1 layer, and turn off 4 the other, automatically

Hello guys,

i have some bigger work in progress and now i would get great use of this functionality to speed up some really tedious tasks...i would really appreciate your help on this topic:

I have 5 layers with most simple naming convention: Layer01, Layer02, Layer03, Layer04 and Layer05....and i need to have one of them turned on, and the rest of them (with this naming convention) turned off automatically, with the click of the button. I would appreciate one case from you, for example for Layer01, and after that, i would modify the script and create several versions of the code, for other layers.

Please see if you can help me with it.

Thank you very much in advance...

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
1rv's picture

Can't you just set up some

Can't you just set up some Scene states with desired layer config?

igamaximus's picture

Scene States vs. Max 2012

I would love to do that , but since i am because of some tools still on Max 2012 x64 and Scene States are painfully buggy (or better say useless) in that version, unfortunately that is not an option for me...

miauu's picture

.

Make tha layer that you want to be ON active. Then run the code. All other layers will become OFF(objects will be hidden). If you want to turn ON other layer - make it active and run the code

(
	curLayer = LayerManager.current
	curLayer.isHidden = false
	for i = 0 to LayerManager.count - 1 where ( (idx=(LayerManager.getLayer i)) != curLayer) do
	(
		idx.isHidden = true
	)	
)
igamaximus's picture

Thank you Kostadin!

Beautiful idea mate, thank you so much for your help!
Now, this works really perfectly except that it works for all layers in the scene. I have some layers, outside of my naming convention that i don't want to be turned off, so please see if is possible to add this functionality to all selected (highlighted on the layers list) layers...this would be so perfect, and if this is not possible...to keep this functionality but only for layers of certain naming convention (ideally, it would be great if i could add number of layers, and layer names in the script).

Thank you so much once again Kostadin, for your quick help and great idea...

miauu's picture

.

The code below works only with 3ds Max 2015 and newer version.

(
	curLayer = LayerManager.current	
 
	layerMngr = SceneExplorerManager.GetActiveExplorer()
	layersArr = layerMngr.SelectedItems()
 
	if layersArr.count != 0 do
	(
		for layer in layersArr do
		(
			layer.isHidden = true
		)
	)	
	curLayer.isHidden = false
)

Select the layers you want to turn OFF and run the code. The active layer will remain ON no matter if it is selected or not, so the layer you want to stay ON must be set as active.

igamaximus's picture

Kostadin,

this is beautiful workflow, but just for the sake of my specific workflow here, can you please write me variant of script where only "Layer01" is turned on, and layers "Layer02", "Layer03", "Layer04" and "Layer05" are turned off, regardless if any of these is selected or not, regardless of current layer, and regardless of any other layer that may be turned on or off? Please!
And if possible, i would like to assign toolbar button to this function so i can do this with 1 click, without even opening Layer Manager...

Thank you!

miauu's picture

.

Save this as a .ms file. Drag and drop it in 3ds Max viewport. Go to Customize-Customize User Interface-miauu category and create a toolbar button.

macroscript turnLayersOnOff
category:"miauu"
tooltip:"Turn Layers On/Off"
buttonText:"Turn Layers On/Off"
(
	(layerManager.getLayerFromName "Layer01").isHidden = false
	(layerManager.getLayerFromName "Layer02").isHidden = true
	(layerManager.getLayerFromName "Layer03").isHidden = true
	(layerManager.getLayerFromName "Layer04").isHidden = true
	(layerManager.getLayerFromName "Layer05").isHidden = true	
)
igamaximus's picture

SHIFT + click to cycle

Kostadin,

can i please ask you for one more addition as i realized this would be the fastest here:
can you please revise this last code (with toolbar button), so when i hold SHIFT key, and press toolbar button, the script would "cycle" on the next layer (turn on next layer, and turn off all the others)?

For example, Layer01 = true and Layers02-05 = false....now when i press the button for the first time, Layer01 will be on, and Layers02-05 will be off. But further, when i hold SHIFT and press the button each next time, next layer (Layer02, Layer03,...up to Layer05) will be ON, and all the others will be off? Would it be too hard to add this?

Thank you so much...
Igor

miauu's picture

.

macroscript turnLayersOnOff
category:"miauu"
tooltip:"Turn Layers On/Off"
buttonText:"Turn Layers On/Off"
(
 
	if keyboard.ShiftPressed then
	(
		layersArr = #("Layer01","Layer02","Layer03","Layer04","Layer05")
		stopLoop = false
		for i = 1 to layersArr.count while stopLoop == false do
		(
			if (layerManager.getLayerFromName ("Layer0" + (i as string))).isHidden == false do
			(
				stopLoop = true
				for j = 1 to layersArr.count do
				(
					(layerManager.getLayerFromName layersArr[j]).isHidden = true
				)
				if i == layersArr.count then
					(layerManager.getLayerFromName layersArr[1]).isHidden = false
				else
					(layerManager.getLayerFromName layersArr[i + 1]).isHidden = false
			)
		)
	)
	else
	(
		(layerManager.getLayerFromName "Layer01").isHidden = false
		(layerManager.getLayerFromName "Layer02").isHidden = true
		(layerManager.getLayerFromName "Layer03").isHidden = true
		(layerManager.getLayerFromName "Layer04").isHidden = true
		(layerManager.getLayerFromName "Layer05").isHidden = true	
	)
)
igamaximus's picture

5x faster!

Kostadin,

this is pure perfection, can't thank you enought for this...
I have used it all day long during the project and i am able to achieve 5x speed improvement comparing to manual clicking in layer manager dialog! Looping is perfect also, exacly what i need!

Thank you SO very much...and also, thank you so much for updating your Spline Deformer - the best tool of its kind for sure!

Wish you all the best with your work and new tools,
Igor

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.