Tag Archives: Instance

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;
}

Select Instance of Object (Max Script)

Select instances of object
This function is select to instances of any object:

fn selectAllInstanceObj obj=
(
	if(obj == undefined) then
	(
		return format"Object undefined" 
	)
	result = #()	
	instanceMgr.getInstances obj &instances	
	instCount = instances.count 
	
	for i = 1 to instCount do
	(
		areRef = ((obj != instances[i]) and not (areNodesInstances obj instances[i]) )
		if( not areRef) then
		(
			join result  #(instances[i])
		)
	)
	
	select result
)

Max Find Only Instance (C++)

Max SDK and C++

Find any object instance using Max SDK and C++
This code block is returned only instance of objects. IInstanceMgr::GetInstanceMgr()->GetInstances functions is finding any object references and instance.But This functions return only instance.

INodeTab MaxSDK::GetInstances(INode *node)
{
    Object *obj = node->GetObjectRef();
    INodeTab instanceAndRef;
    IInstanceMgr::GetInstanceMgr()->GetInstances(*node, instanceAndRef);
    INodeTab onlyInstance;

    for (int k=0; k < instanceAndRef.Count(); k++)
    {
        if (obj == instanceAndRef[k]->GetObjectRef())
		{
			onlyInstance.AppendNode(instanceAndRef[k]);
		}
    }
    return onlyInstance;
}