画几条curve,选中,然后post1,沿着curve画出5个cylinder
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MString.h>
#include <maya/MDagPath.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MPoint.h>
// Use helper macro to register a command with Maya. It creates and
// registers a command that does not support undo or redo. The
// created class derives off of MPxCommand.
//
class Posts1Cmd : public MPxCommand
{
public:
virtual MStatus doIt( const MArgList& args );
static void *creator(){return new Posts1Cmd;}
};
MStatus Posts1Cmd ::doIt( const MArgList& args )
{
const int nPosts = 5;
const double radius = 0.5;
const double height = 0.5;
MSelectionList selection;
MGlobal::getActiveSelectionList(selection);
MDagPath dagPath;
MFnNurbsCurve curveFn;
double heightRatio = height / radius;
MItSelectionList iter(selection , MFn::kNurbsCurve);
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath(dagPath);
curveFn.setObject(dagPath);
double tStart,tEnd;
curveFn.getKnotDomain(tStart, tEnd );
MPoint pt;
unsigned int i;
double t;
double tIncr = (tEnd - tStart )/(nPosts - 1 );
for ( i=0, t=tStart; i<nPosts; i++, t+=tIncr )
{
curveFn.getPointAtParam( t, pt, MSpace::kWorld);
pt.y += 0.5 * height;
MGlobal::executeCommand( MString("cylinder -pivot ") + pt.x + " " + pt.y + " " + pt.z + "-radius 0.5 -axis 0 1 0 -heightRatio " + heightRatio );
}
}
return MS::kSuccess;
}
MStatus initializePlugin(MObject obj)
{
MFnPlugin pluginFn(obj,"lijy","1.0");
MStatus stat;
stat = pluginFn.registerCommand("post1",Posts1Cmd::creator);
if(!stat)
stat.perror("registerCommand failed");
return stat;
}
MStatus uninitializePlugin(MObject obj)
{
MFnPlugin pluginFn(obj);
MStatus stat;
stat = pluginFn.deregisterCommand("post1");
if(!stat)
stat.perror("deregisterCommand failed");
return stat;
}