![]()
Basic Program example
The following is a basic Dt based plug-in that queries the selected objects and outputs the name of the shape (mesh) and any “color” texture file names that are mapped to the shader.
#include <maya/MSimple.h> #include <MDt.h> #include <MDtExt.h> DeclareSimpleCommand( basic, "Alias - Example", "2.0"); void outputFileNames() { char *shapeName; char *mtlName; char *texName; // 1st thing find out how many shapes (meshes) are in this scene // currently being looked at. int numShapes = DtShapeGetCount(); // For each shape, check out what is assigned as the color texture // There may not be a texture associated with material, or the texture // may be a procedural texture and so have no file name. for ( int shape=0; shape < numShapes; shape++ ) { // Find the name of the current shape that we are looking at. DtShapeGetName( shape, &shapeName ); // Find out the number of groups (materials) assigned to this shape numGroups = DtGroupGetCount( shape ); // For each group (material) check out to see if there is a file texture // associated with the material and output its name. // It is possible that the number of groups will be zero. In this case // there would be no materials assigned: // 1) Joint or other Transform node // 2) user deleted all of the materials including the default shading group // 3) removed the connections between the mesh and the shading groups. // Usual reason is #1, a Joint or straight Transform node. (when using // full hierarchy mode for ( int group=0; groups < numGroups; group++ ) { // For the current shape+group combination find out its material DtMtlGetName( shape, group, &mtlName ); // For the current material, find out its texture file name if any DtTextureGetFileName( mtlName, &texName ); // output any information that is wanted about what we found above. printf( "for shape %s(%d) group %s(%d), texture filename is %s\n", shapeName, shape, mtlName, group, texName ? texName : "(NULL)" ); } } } // // main doIt function for the plugin command. MStatus basic::doIt( const MArgList& args ) { // Initialize the Dt database DtExt_SceneInit( “basic” ); // using the default settings, as no initializer // functions are called here // Walk the dag and fill in the internal database DtExt_initdb(); // walk thru shapes found and output the texture file names outputFileNames(); // Clean up the allocated memory and internal storage DtExt_CleanUp(); // return from the plugin command return MS::kSuccess; }