xmlAssembly/FnAssetInstanceUtil.h
 
 
 
xmlAssembly/FnAssetInstanceUtil.h
#ifndef _FnAssetInstanceUtil_H
#define _FnAssetInstanceUtil_H

//-
//**************************************************************************/
// Copyright 2012 Autodesk, Inc. All rights reserved. 
//
// Use of this software is subject to the terms of the Autodesk 
// license agreement provided at the time of installation or download, 
// or which otherwise accompanies this software in either electronic 
// or hard copy form.
//**************************************************************************/
//+

#include <maya/MObject.h>
#include <maya/MObjectArray.h>
#include <maya/MPlug.h>

namespace FnAssetInstanceUtil
{
        //find all the objects which is both in arrayA and in arrayB
        template<typename T>
        void getIntersection( const T& arrayA, const T& arrayB, T& result)
        {
                for( unsigned int i = 0; i < arrayA.length(); ++i)
                {
                        for( unsigned int j = 0; j < arrayB.length(); ++j)
                        {
                                if( arrayA[ i] == arrayB[ j])
                                {
                                        result.append( arrayA[ i]);
                                }
                        }
                }
        }

        //find all the objects which is in arrayA but not in arrayB
        template<typename T>
        void getSupplementary( const T& arrayA, const T& arrayB, T& result)
        {
                for( unsigned int i = 0; i < arrayA.length(); ++i)
                {
                        bool found = false;
                        for( unsigned int j = 0; j < arrayB.length(); ++j)
                        {
                                if( arrayA[ i] == arrayB[ j])
                                {
                                        found = true;
                                        break;
                                }
                        }
                        if (!found)
                        {
                                result.append( arrayA[ i]);
                        }
                }
        }

void getAttributePlug( const MObject& containerName, const MString& attributeName, MPlug& outPlug);

void containerManipulator( MObject& containerName, const MObjectArray& nodes, bool isAdd = true, bool isForce = false);

bool addNodes( MObject& containerName, const MObjectArray& nodes, bool isForce = false);
bool addNodes( MObject& containerName, const MObject& node, bool isForce = false);

void removeNodes( MObject& containerName, MObjectArray& nodeList);

void hideNodes( MObject& containerName, MObjectArray& nodeList);
void showNodes( MObject& containerName, MObjectArray& nodeList);

bool isAssetInstance( const MObject& dagNode);
void findAssetMembers( const MObject& containerName, const MObjectArray& nodeList, MObjectArray& results);

template< typename T>
void setAttributeValue( MObject& containerName, const MString& attributeName, const T& attriValue)
{
        MPlug attributePlug;
        getAttributePlug( containerName, attributeName, attributePlug);
        attributePlug.setValue( attriValue);
}

template< typename T>
void getAttributeValue( const MObject& containerName, const MString& attributeName, T& outValue)
{
        MPlug attributePlug;
        getAttributePlug( containerName, attributeName, attributePlug);
        attributePlug.getValue( outValue);
}

}

#endif