Clear out the dead wood from the layer manager

62 votes
Author: 
LoneRobot

Clear out the dead wood from the layer manager

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.

layermanager

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

Macroscript ClearEmptyLayers

category:"LoneRobot"

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

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"

 

)

 

after -

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.

Application Version: 
Max2010

Comments

Comment viewing options

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

Well it seems understandable

Well it seems understandable now to me. I am glad I managed to find a post that helped me to figure out this everything here, to my mind this topic is pretty much important and probably even essential.

LoneRobot's picture

Thanks for posting that, not

Thanks for posting that, not sure why the quotes got messed up, main body text is fixed now too.

MrTyner's picture

fix

for some reason the quotes were messed up. This should work for you

(
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.name
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"
)

Script_Butler's picture

When I copy and paste this

When I copy and paste this script in to the MAXScript Listener i get this

-- Syntax error: at ), expected
-- In line: )

Max 2010 SP1

Any ideas?

Cheers.

Script_Butler

pifitas's picture

Hi, seems yo be a nice

Hi, seems yo be a nice script

can you explain me how to make it work or even better: make a ms file please? I don't know anything about scripts :(

thank you!!!

Comment viewing options

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