I want to create a NURBS curve in Maya through a MEL script, bind it to my plugin and simply update the CVs in the plugin (and in the viewport). The problem is that I don't think it's possible to read and write to the same shape. Here is the MEL code:
curve -p 0 10 0 -p 5 0 0 -p 5 0 5 -p 0 0 5;
createNode FurrySystemNode -n furry;
connectAttr time1.outTime furry.time;
connectAttr curveShape1.local furry.input_curve;
connectAttr furry.output_curve curveShape1.create
Where input_curve
and output_curve
are typed attributes in the plugin. It fails when trying to create the MFnNurbsCurve
because curve_obj
is null. If I write to another shape as output it works just fine.
MStatus FurrySystemNode::compute(const MPlug& plug, MDataBlock& data) {
if (plug == output_curve) {
cout << "Computing input_curve\n";
MStatus stat;
MDataHandle handle = data.inputValue(input_curve, &stat);
MDataHandle output_handle = data.outputValue(output_curve, &stat);
McheckErr(stat, "Failed at getting data.inputValue\n");
MObject curve_obj = handle.data();
MFnNurbsCurve curve_fn(curve_obj, &stat);
McheckErr(stat, "Failed at creating the MFnNurbsCurve function set\n"); // Fails here
MPointArray cvs;
stat = curve_fn.getCVs(cvs, MSpace::kWorld);
for (int i = 0; i < cvs.length(); i++) {
cvs[i] += MPoint(i, 0, 0);
}
curve_fn.setCVs(cvs, MSpace::kWorld);
curve_fn.updateCurve(); // Don't think this one is needed
output_handle.set(curve_obj);
stat = data.setClean(plug);
McheckErr(stat, "Failed at cleaning data\n");
}
return MS::kSuccess;
}
Any ideas?