Function:
Create a bunch of cylinders along the selected curve. The number of cylinders, the radius and the height can be specified through parameters.
Main Code:
MStatus Posts1Cmd::doIt(const MArgList &args)
{
int nPosts=5;
double radius=0.5;
double height=5.0;
unsigned index;
index=args.flagIndex("n", "number");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1,nPosts);
index=args.flagIndex("r","radius");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1, radius);
index=args.flagIndex("h", "height");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1,height);
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;
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 "+radius+" -axis 0 1 0 -heightRatio "+heightRatio);
}
}
return MS::kSuccess;
}
Snapshot:
No comments:
Post a Comment