Flatten layer hierarchy


I’m sorry for bombarding the forum with questions lately, but I was wondering if there’s some way to flatten the hierarchy of the Layers in 3dsMax? Whenever I create a new layer with another one selected, it adds it below the current one. I would like to create a script that just flattens the hierarchy of all of my layers if possible?

fn flattenLayer layer = 
	res = false
	while (layer.getNumChildren() > 0) do
		res = res or (LayerManager.deleteLayerHierarchy (layer.getChild 1).name forceDelete:on) 	
fn flattenLayerByName name = 
	layer = LayerManager.getLayerFromName name
	if layer != undefined do flattenLayer layer

flatten all:

fn flattenAllLayers = 
	layers = for k=0 to LayerManager.count-1 where (layer = LayerManager.getLayer k).getParent() == undefined collect layer
	for layer in layers do flattenLayer layer

	for i = 1 to layerManager.count where (layer = (layerManager.getLayer i)) != undefined do layer.setParent undefined


this is not what was asked as I guess…


Honestly, I don’t know what “Flatten layer hierarchy” means. :slight_smile:


merge nested layer nodes to parent and delete empty … that’s what I guess


I tought of flattening a hierarchy as if you would unparent any node from a hierarchy, so miauu’s solution did exactly what I wanted. I should have been able to find the setParent flag from the documentation though, but it seems I missed it :face_with_raised_eyebrow:

Thank you both. :slight_smile:


but you were right, i was wrong