#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class preSmooth : public MPxCommand { public: preSmooth() {}; virtual ~preSmooth(); static void* creator(); MStatus doIt ( const MArgList& args ); MObject newTransform; MDGModifier dgModifier; }; preSmooth::~preSmooth(){} void* preSmooth::creator() { return new preSmooth(); } MStatus preSmooth::doIt( const MArgList& args ) { MStatus status; MObject node; MFnDependencyNode depFn; MDagPath dagPath; MString cmd, smoothObjName, smoothShape, smoothFacet; MString shapeName, shapeType, connectSG; MStringArray resultCmd;=09 MString version =3D MGlobal::mayaVersion(); =09 MSelectionList sList; MGlobal::getActiveSelectionList( sList ); MItSelectionList itsl( sList ); for ( ; !itsl.isDone(); itsl.next() )=20 { itsl.getDagPath( dagPath ); MFnDagNode dagFn( dagPath, &status ); if ( !status ) { MGlobal::displayError( "Can't!!" ); return status; } itsl.getDependNode( node ); depFn.setObject( node ); MString nodeName =3D depFn.name(); MString nodeType =3D depFn.typeName(); if ( nodeType=3D=3D"transform" ) { MGlobal::selectByName( nodeName ); cmd =3D "listRelatives -s " + nodeName; MGlobal::executeCommand( cmd, resultCmd ); shapeName =3D resultCmd[0]; =09 cmd =3D "nodeType " + shapeName; MGlobal::executeCommand( cmd, shapeType ); =09 if ( shapeType=3D=3D"mesh" ) { smoothObjName =3D nodeName + "Smooth"; MGlobal::selectByName( nodeName ); cmd =3D "duplicate -n " + smoothObjName; MGlobal::executeCommand( cmd ); cmd =3D "listRelatives -s " + smoothObjName; MGlobal::executeCommand( cmd, resultCmd ); smoothShape =3D resultCmd[0]; cmd =3D "connectAttr -f " + nodeName + ".outMesh " + smoothShape + = ".inMesh"; MGlobal::executeCommand( cmd ); cmd =3D "polySmooth -dv 1 -c 1 -ch 1 " + smoothShape; MGlobal::executeCommand( cmd, resultCmd ); smoothFacet =3D resultCmd[0]; if ( version=3D=3D"3.0" || version=3D=3D"30a" )=20 { cmd =3D "setAttr " + smoothFacet + ".inputComponents"; cmd +=3D " -type \"componentList\" 1 \"f[*]\""; MGlobal::executeCommand( cmd ); =09 } else { cmd =3D "listConnections -s on -d off -t makeGroup " + smoothFacet; MGlobal::executeCommand( cmd, resultCmd ); MString inMakeGrp =3D resultCmd[0]; =09 cmd =3D "setAttr " + inMakeGrp + ".inputComponents"; cmd +=3D " -type \"componentList\" 1 \"f[*]\""; MGlobal::executeCommand( cmd ); } =09 cmd =3D "connectionInfo -dfs " + shapeName + ".instObjGroups[0]"; MGlobal::executeCommand( cmd, resultCmd ); if ( resultCmd[0]!=3D"\0" ) { for ( unsigned int h=3D0; h