how can one enumerate hierarchy of nested layers using max 2015 sdk. Example: I have 3 layers named simply "1","2" and "3". 1 and 2 are at the root and 3 belongs in to 1.
How to find out this information using sdk.
I can find a layer where a node belongs:
layer = (ILayer*)(node->GetReference(NODE_LAYER_REF));
In the ILayer interface, I cannot find any information about it's parent. I can get some "extended" (?) properties of the layer:
props = (ILayerProperties*)layer->GetInterface(LAYERPROPERTIES_INTERFACE);
There isn't any relevant information to my problem either.
I can access layer manager:
manager = (ILayerManager*) GetCOREInterface()->GetScenePointer()->GetReference(10);// don't remember where did I dig out the magic number 10
Here I can enumerate all layers by index, but not by hierarchy.
Any help would be appreciated. Thanks.
The documentations says this:
Iterating over Layers by Index: The IFPLayerManager class is also an interface class that manages scene layers in 3ds Max. This class however is a function published interface, and thus is quite different from the previously discussed layer manager. This class is the C++ interfaces to the MAXScript LayerManager class. This class has a useful method fro returning a layer by integer index. Thus you can iterate over scene layers without knowing the names of the layers. To get a pointer to this object you call the GetCOREInterface() function.
IFPLayerManager* layer_manager = static_cast< IFPLayerManager*> GetCOREInterface( LAYERMANAGER_INTERFACE);
The LAYERMANAGER_INTERFACE identifies the IFPLayerManager interface. With the resulting pointer you can get a scene layer by integer index.
ILayerProperties* hLayer = layer_manager->getLayer(i);
This IFPLayerManager::getLayer() method returns a ILayerProperties pointer which has much less functionality than ILayer.
To get an ILayer pointer you can get a pointer to any object on that layer, and extract the ILayer pointer from it.
The ILayerProperties class has functions for child\parent layers:
virtual ILayerProperties* getChildLayerProperties ( int n ) const
Remarks Returns a pointer to the Nth child Layer properties for this layer. Parameters: int n
The index of the child layer properties. Returns Returns a pointer to the Nth child layer properties.
virtual ILayerProperties* getParentLayerProperties ( ) const pure virtual
Remarks Returns the parent Layer. This could be NULL meaning the layer is at the top level.
Which means you can loop through all by index, then check if it's a parent layer, if it is then loop through all it's child layers, then move on to the next one.
These functions are documented in the 'ILayerProperties Class Reference' in the 3dsmax SDK documentation.