Tag Archives: InstanceMgr

Get Instance of Node C#

Get Instance of Node C#
This function return only instance of any node.

//global is your start IGlobal object
private Autodesk.Max.INodeTab GetNodeInstances(IGlobal global,IINode node)
{
	IObject obj = node.ObjectRef;
	Autodesk.Max.INodeTab instanceAndRef = global.NodeTab.Create();
	Autodesk.Max.INodeTab result = global.NodeTab.Create();

	global.IInstanceMgr.InstanceMgr.GetInstances(node, instanceAndRef);

	IntPtr indexer ;
	
	for (int i = 0; i < instanceAndRef.Count; i++)
	{
		indexer = new IntPtr(i);

		if (obj.Handle == instanceAndRef[indexer].ObjectRef.Handle)
		{
			result.InsertNode(instanceAndRef[indexer], result.Count, true);
		}

		Marshal.FreeHGlobal(indexer);
	}

	return result;
}