Example #1
0
MStatus PRTAttrs::addParameter(MFnDependencyNode & node, MObject & attr, MFnAttribute& tAttr) {
	if(!(node.hasAttribute(tAttr.shortName()))) {
		MCHECK(tAttr.setKeyable (true));
		MCHECK(tAttr.setHidden(false));
		MCHECK(tAttr.setStorable(true));
		MCHECK(node.addAttribute(attr));
	}
	return MS::kSuccess;
}
    //---------------------------------------------------
    MPlug DagHelper::getChildPlug ( const MPlug& parent, const MString& name, MStatus* rc )
    {
        MStatus st;
        uint childCount = parent.numChildren ( &st );
        if ( st != MStatus::kSuccess )
        {
            if ( rc != NULL ) *rc = st;
            return parent;
        }

        // Check shortNames first
        for ( uint i = 0; i < childCount; ++i )
        {
            MPlug child = parent.child ( i, &st );
            if ( st != MStatus::kSuccess )
            {
                if ( rc != NULL ) *rc = st;
                return parent;
            }

            MFnAttribute attributeFn ( child.attribute() );
            MString n = attributeFn.shortName();
            if ( n == name )
            {
                if ( rc != NULL ) *rc = MStatus::kSuccess;
                return child;
            }
        }

        // Check longNames second, use shortNames!
        for ( uint i = 0; i < childCount; ++i )
        {
            MPlug child = parent.child ( i, &st );
            if ( st != MStatus::kSuccess )
            {
                if ( rc != NULL ) *rc = st;
                return parent;
            }

            MFnAttribute attributeFn ( child.attribute() );
            MString n = attributeFn.name();
            if ( n == name )
            {
                if ( rc != NULL ) *rc = MStatus::kSuccess;
                return child;
            }
        }

        if ( rc != NULL ) *rc = MStatus::kNotFound;
        return parent;
    }
    //---------------------------------------------------
    int DagHelper::getChildPlugIndex ( const MPlug& parent, const MString& name, MStatus* rc )
    {
        MStatus st;
        uint childCount = parent.numChildren ( &st );
        CHECK_STATUS_AND_RETURN ( st, -1 );

        // Check shortNames first
        for ( uint i = 0; i < childCount; ++i )
        {
            MPlug child = parent.child ( i, &st );
            CHECK_STATUS_AND_RETURN ( st, -1 );

            MFnAttribute attributeFn ( child.attribute() );
            MString n = attributeFn.shortName();

            if ( n == name )
            {
                if ( rc != NULL ) *rc = MStatus::kSuccess;

                return i;
            }
        }

        // Check longNames second, use shortNames!
        for ( uint i = 0; i < childCount; ++i )
        {
            MPlug child = parent.child ( i, &st );
            CHECK_STATUS_AND_RETURN ( st, -1 );

            MFnAttribute attributeFn ( child.attribute() );
            MString n = attributeFn.name();

            if ( n == name )
            {
                if ( rc != NULL ) *rc = MStatus::kSuccess;

                return i;
            }
        }

        if ( rc != NULL ) *rc = MStatus::kNotFound;

        return -1;
    }
Example #4
0
//for this attribute on this node add the following layer nodes and plugs it's associated with
void atomNodeWithAnimLayers::addPlugWithLayer(MPlug &attrPlug, MObjectArray &layers, MPlugArray &plugs)
{
	if(plugs.length() == layers.length())
	{
		MObject attrObj = attrPlug.attribute();
		MFnAttribute fnLeafAttr (attrObj);
		std::string attrStd(std::string(fnLeafAttr.name().asChar()));
		PlugsAndLayers plugsAndLayers;
		for(unsigned int i =0; i < layers.length(); ++i)
		{
			if(plugs[i].isNull()==false) //it's possible to not have a plug for the specified layer
			{
				if(layers[i].hasFn (MFn::kDependencyNode))
				{
					MFnDependencyNode fnNode (layers[i]);
					MString layerName = fnNode.name();
					plugsAndLayers.mLayerNames.append(layerName);
					plugsAndLayers.mPlugs.append(plugs[i]);
					fAttrLayers[attrStd] = plugsAndLayers;
				}
			}
		}
	}
}
Example #5
0
MStatus getAttrAffects::doIt( const MArgList& args )
{
	MStatus stat;
	MSelectionList list;

	if ( args.length() > 0 ) {
		// Arg list is > 0 so use objects that were passes in
		//
		MString argStr;

		unsigned last = args.length();
		for ( unsigned i = 0; i < last; i++ ) {
			// Attempt to find all of the objects matched
			// by the string and add them to the list
			//
			args.get( i, argStr );  
			list.add( argStr ); 
		}
	} else {
		// Get the geometry list from what is currently selected in the 
		// model
		//
		MGlobal::getActiveSelectionList( list );
	} 
	MItSelectionList iter( list );

	// Iterate over all selected dependency nodes
	//
	for ( ; !iter.isDone(); iter.next() ) 
	{
		MObject object;

		stat = iter.getDependNode( object );
		if ( !stat ) {
			stat.perror("getDependNode");
			continue;
		}

		// Create a function set for the dependency node
		//
		MFnDependencyNode node( object );

		cout << node.name() << ":\n";
		unsigned i, numAttributes = node.attributeCount();

		for (i = 0; i < numAttributes; ++i) {
			MObject attrObject = node.attribute(i);
			MFnAttribute attr;
			unsigned j, affectedLen, affectedByLen;

			attr.setObject (attrObject);

			// Get all attributes that this one affects
			MObjectArray affectedAttributes;
			node.getAffectedAttributes( attrObject, affectedAttributes );
			affectedLen = affectedAttributes.length();

			// Get all attributes that affect this one
			MObjectArray affectedByAttributes;
			node.getAffectedByAttributes( attrObject, affectedByAttributes );
			affectedByLen = affectedByAttributes.length();

			if ( affectedLen > 0 || affectedByLen > 0 ) {
				cout << "  " << attr.name() << ":\n";

				// List all attributes that are affected by the current one
				if ( affectedLen > 0 ) {
					cout << "    Affects(" << affectedLen << "):";

					for (j = 0; j < affectedLen; ++j ) {
						attr.setObject ( affectedAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}

				// List all attributes that affect the current one
				if ( affectedByLen > 0 ) {
					cout << "    AffectedBy(" << affectedByLen << "):";

					for (j = 0; j < affectedByLen; ++j ) {
						attr.setObject ( affectedByAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}
			}
		}
	}
	return MS::kSuccess;
}