Flatten layer hierarchy


#1

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?


#2
fn flattenLayer layer = 
(
	res = false
	while (layer.getNumChildren() > 0) do
	(
		res = res or (LayerManager.deleteLayerHierarchy (layer.getChild 1).name forceDelete:on) 	
	)
	res
)
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
)

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

#4

this is not what was asked as I guess…


#5

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


#6

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


#7

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:


#8

but you were right, i was wrong