Notifications
Clear all

[Closed] Clean unused layers in the layer palette script

Can someone help me with this. Because of the complexity of our models we use the layer palette here on every project. All of our renders originate from a huge ‘master’ model.

My question is, can someone figure out how to select all empty unused layers in the layer palette and delete them with script. Something I can place on a button or in a quad menu? Right now we can have 100 layers in the layer palette and after we are done deleting components to create custom files from the ‘master’ model it creates a lot of empty layers that need to be cleaned out of the layer palette. I normally like to hand down a clean layer palette file because it’s just a lot easier on the next artist. Right now I have to manually look for empty layers and it can be quite time consuming depending on the amount of layers. Would be better if it could be automated.

Is this even possible? Thanks for any help.

6 Replies

something like this?


for i = (layerManager.count - 1) to 1 by -1 do (
	local curLayer = layerManager.getLayer i
	local curLayerNodes
	curLayer.nodes &curLayerNodes
	if (curLayerNodes.count == 0) then (
		local curLayerName = curLayer.name
		format "Deleting empty layer: %
" curLayerName
		layerManager.deleteLayerByName curLayerName
	)
)

Basically it…

  • loops over all layers, starting at the back (note that it subtracts 1 because the .count includes the base layer – which is not actually accessible) and working its way to the front; the reason for this is that while we delete layers, the indices will change as well – working from back to front means we don’t have to worry about that
  • gets the layer’s nodes list into the by-reference variable
  • checks if there are zero nodes in that list
  • prints a little message to let you know what it deletes/deleted, and deletes the layer

PERFECT! PERFECT! PERFECT!

I know it’s the small things but when you do it day in day out, it’s like, there must be a way to speed this up. You have done it Richard. This will be used everyday and I am going to keep this tucked away for safe keeping.

Awesome! Thank you so much!

no prob

I am pretty sure you can simplify the script to just try to delete each layer since according to the documentation, delete only works on empty non-current layers anyway. So you can just loop and delete and those with no objects will be deleted while the rest will stay.

Yeah, but…


for i = (layerManager.count - 1) to 1 by -1 do (
	layerManager.deleteLayerByName (layerManager.getLayer i).name
)

…where’s the fun in that?

And with the layer name format thing…


for i = (layerManager.count - 1) to 1 by -1 do (
	if (layerManager.deleteLayerByName (layerName = (layerManager.getLayer i).name)) then (
		format "Deleted empty layer: %
" layerName
	)
)

Here’s an old script of mine which removes unwanted layers. I haven’t touched it in years so it can probably be optimized a lot, but I still use it occasionaly (mainly to cleanup CAD data) and it does the job

Martijn