Notifications
Clear all

[Closed] collect scene layers from maxfile

How could I go about recursively collecting the layers from a maxfile. For example say i have a file like the image attached. Each array has the name of the layer and the a children field which contains it’s child layers.

How could i return nested arrays matching the hierarchy like this:


struct layer_data (name="", childlayers=#())

scene_layers = #(
	#(name:"_REF" childlayers:#())
	#(name:"0" childlayers:#(
		#(name:"A_01" childlayers:#(
			#(name:"A_02" childlayers:#()
		)
	))
	...	
)

screenshot

1 Reply

there you go:


(
	scene_layers = #()
	struct layer_data (name="", childlayers=#())

	fn recursiveStoreLayerFn layer parentStruct:undefined =
	(
		curSt = layer_data()
		curSt.name = layer.name
		if parentStruct != undefined then append parentStruct.childlayers curSt else append scene_layers curSt
		for i = 1 to layer.getNumChildren() do recursiveStoreLayerFn (layer.getChild i) parentStruct:curSt
	)

	for i = 0 to layerManager.count-1 do
	(
		curLayer = layerManager.getLayer i
		if curLayer.getParent() == undefined do recursiveStoreLayerFn curLayer
	)
	
	print scene_layers
)