Clear out the dead wood from the layer manager

Mar 16, 2010 by     2 Comments    Posted under: 3dsMax, Maxscript, Tips and Tricks

Occasionally, you end up with a load of layers in your scene that are no use to anybody, serve no function to society, and end up taking valuable space like an unwanted uncle at a wedding.


Here is a macro that will check the layer manager interface and remove any layer that is empty.

Macroscript ClearEmptyLayers 
tooltip:"Clear Empty Layers" 
buttontext:"Clear Layers" 

DeletedLayerCount = 0 
local deflayer = layermanager.getlayer 0 
deflayer.current = true
for i = Layermanager.count-1 to 1 by-1 do
		layer = layermanager.getLayer i  
		local thislayername = 
		layer.nodes &theNodes  
		if thenodes.count== 0 then (LayerManager.deleteLayerbyname thislayername;DeletedLayerCount +=1)
	if not DeletedLayerCount == 0 then Messagebox ("Number of layers removed - " + DeletedLayerCount as string) title:"Layer Manager" 

And after –


If only it was that easy to remove Piers Morgan from ‘the scene’

One thing to note is how the layermanager interface retrieves the contents of the layer –

if thenodes.count== 0 then …

The ampersand before the variable declares an array to be used and populates it with the layer contents. You might also notice that it deletes the layers in reverse order, since each time you delete one, the layer count becomes less. So if you deleted it going forward you would probably reach a point where the loop integer would be higher than the number of remaining layers, boo.

You also have to minus one from the total count as the default layer is located at 0.