//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ #include #include #include #include #include #include #include #include #include #include #include #include // // This small example illustrates that a node of a particular type can be found // by walking through the DG graph. In this example, the nodes of type // fileTexture has to be found. The plugin will start from the shape node that // the user selected, or the ones passing in as parameters. It then look for a // connection to the shadingEngine. Once found, it will use a dependency graph // iterator with a filter that matches the type desire to iterate through the // connections to the shadingEngine. // void dumpInfo( MObject fileNode, MFnDependencyNode& nodeFn, MObjectArray& nodePath ) { MObject currentNode; MObject fileAttr = nodeFn.attribute("fileTextureName"); MPlug plugToFile( fileNode, fileAttr ); MFnDependencyNode dgFn; MStatus stat; cerr << "Name: " << nodeFn.name() << endl; MObject fnameValue; stat = plugToFile.getValue( fnameValue ); if ( !stat ) { stat.perror("error getting value from plug"); } else { MFnStringData stringFn( fnameValue ); cerr << "Texture: " << stringFn.string() << endl; } cerr << "Path: "; for ( int i = nodePath.length()-1; i >= 0; i-- ) { currentNode = nodePath[i]; dgFn.setObject( currentNode ); cerr << dgFn.name() << "(" << dgFn.typeName() << ")"; if ( i > 0) cerr << " ->\n "; } cerr << endl; } DeclareSimpleCommand( findFileTextures, "Alias", "3.0"); MStatus findFileTextures::doIt( const MArgList& args ) { MSelectionList list; MStatus status; 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 arguments from Maya's selection list. MGlobal::getActiveSelectionList( list ); } MObject node; MFnDependencyNode nodeFn,dgNodeFnSet; MItDependencyGraph* dgIt; MObject currentNode; MObject thisNode; MObjectArray nodePath; for ( MItSelectionList iter( list ); !iter.isDone(); iter.next() ) { iter.getDependNode( node ); // // The following code shows how to navigate the DG manually without // using an iterator. First, find the attribute that you are // interested. Then connect a plug to it and see where the plug // connected to. Once you get all the connections, you can choose // which route you want to go. // // In here, we wanted to get to the nodes that instObjGroups connected // to since we know that the shadingEngine connects to the instObjGroup // attribute. // nodeFn.setObject( node ); MObject iogAttr = nodeFn.attribute( "instObjGroups", &status); if ( !status ) { cerr << nodeFn.name() << ": is not a renderable object, skipping\n"; continue; } MPlug iogPlug( node, iogAttr ); MPlugArray iogConnections; // // instObjGroups is a multi attribute. In this example, just the // first connection will be tried. // iogPlug.elementByLogicalIndex(0).connectedTo( iogConnections, false, true, &status ); if ( !status ) { cerr << nodeFn.name() << ": is not in a shading group, skipping\n"; continue; } // // Now we would like to traverse the DG starting from the shadingEngine // since most likely all file texture nodes will be found. Note the // filter used to initialize the DG iterator. There are lots of filter // type available in MF::Type that you can choose to suite your needs. // bool foundATexture = false; for ( unsigned int i=0; idisablePruningOnFilter(); for ( ; ! dgIt->isDone(); dgIt->next() ) { thisNode = dgIt->thisNode(); dgNodeFnSet.setObject( thisNode ); status = dgIt->getNodePath( nodePath ); if ( !status ) { status.perror("getNodePath"); continue; } // // append the starting node. // nodePath.append(node); dumpInfo( thisNode, dgNodeFnSet, nodePath ); foundATexture = true; } delete dgIt; } if ( !foundATexture ) { cerr << nodeFn.name() << ": is not connected to a file texture\n"; } } return MS::kSuccess; }