public override void doIt(MArgList args /*, MPxCommandClass cmd*/) { // This method is called from script when this command is called. // It should set up any class data necessary for redo/undo, // parse any given arguments, and then call redoIt. MArgDatabase argData = new MArgDatabase(/*cmd.*/ syntax, args); __isIndex = argData.isFlagSet(kIndexFlag); // Get the plug specified on the command line. MSelectionList slist = argData.SelectionObjects; if (slist.length == 0) { throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args"); } __fPlug = slist.getPlug(0); if (__fPlug == null) { throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args"); } // Construct a data handle containing the data stored in the plug. MDataHandle dh = new MDataHandle(); try { __fPlug.getValue(dh); } catch (Exception) { throw new ApplicationException("Could not get the plug value."); } MArrayDataHandle adh; uint indx = 0; try { adh = new MArrayDataHandle(dh); } catch (Exception) { __fPlug.destructHandle(dh); throw new ApplicationException("Could not create the array data handle."); } // Iterate over the values in the multiPlug. If the index flag has been used, just return // the logical indices of the child plugs. Otherwise, return the plug values. string errorMsg = null; for (uint i = 0; i < adh.elementCount(); i++, adh.next()) { try { indx = adh.elementIndex(); } catch (Exception) { continue; } if (__isIndex) { appendToResult((int)indx); } else { MDataHandle h = adh.outputValue(); if (h.isNumeric) { switch (h.numericType) { case MFnNumericData.Type.kBoolean: appendToResult(h.asBool); break; case MFnNumericData.Type.kShort: appendToResult(h.asShort); break; case MFnNumericData.Type.kInt: appendToResult(h.asInt); break; case MFnNumericData.Type.kFloat: appendToResult(h.asFloat); break; case MFnNumericData.Type.kDouble: appendToResult(h.asDouble); break; default: errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n", errorMsg != null ? errorMsg : "", h.numericType.ToString()); break; } } } } __fPlug.destructHandle(dh); if (errorMsg != null) { throw new ApplicationException(errorMsg); } ; return; }
public override void doIt(MArgList args/*, MPxCommandClass cmd*/) { // This method is called from script when this command is called. // It should set up any class data necessary for redo/undo, // parse any given arguments, and then call redoIt. MArgDatabase argData = new MArgDatabase(/*cmd.*/syntax, args); __isIndex = argData.isFlagSet(kIndexFlag); // Get the plug specified on the command line. MSelectionList slist = argData.SelectionObjects; if ( slist.length == 0 ) { throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args"); } __fPlug = slist.getPlug (0) ; if ( __fPlug == null ) { throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args"); } // Construct a data handle containing the data stored in the plug. MDataHandle dh = new MDataHandle() ; try { __fPlug.getValue(dh); } catch (Exception) { throw new ApplicationException("Could not get the plug value."); } MArrayDataHandle adh ; uint indx =0 ; try { adh = new MArrayDataHandle(dh); } catch (Exception) { __fPlug.destructHandle(dh) ; throw new ApplicationException("Could not create the array data handle."); } // Iterate over the values in the multiPlug. If the index flag has been used, just return // the logical indices of the child plugs. Otherwise, return the plug values. string errorMsg = null; for (uint i = 0; i < adh.elementCount(); i++, adh.next()) { try { indx = adh.elementIndex() ; } catch (Exception) { continue ; } if ( __isIndex ) { appendToResult ((int)indx) ; } else { MDataHandle h = adh.outputValue () ; if (h.isNumeric) { switch (h.numericType) { case MFnNumericData.Type.kBoolean: appendToResult (h.asBool) ; break; case MFnNumericData.Type.kShort: appendToResult (h.asShort) ; break; case MFnNumericData.Type.kInt: appendToResult (h.asInt) ; break; case MFnNumericData.Type.kFloat: appendToResult (h.asFloat) ; break; case MFnNumericData.Type.kDouble: appendToResult (h.asDouble) ; break; default: errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n", errorMsg != null ? errorMsg : "", h.numericType.ToString()); break; } } } } __fPlug.destructHandle (dh) ; if (errorMsg != null) throw new ApplicationException(errorMsg); ; return; }
public override bool compute(MPlug plug, MDataBlock block) { if (plug.equalEqual(constraintGeometry)) { // block.inputValue(constraintParentInverseMatrix); // MArrayDataHandle targetArray = block.inputArrayValue(compoundTarget); uint targetArrayCount = targetArray.elementCount(); double weight, selectedWeight = 0; if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight) { selectedWeight = float.MaxValue; } MObject selectedMesh = null; uint i; for (i = 0; i < targetArrayCount; i++) { MDataHandle targetElement = targetArray.inputValue(); weight = targetElement.child(targetWeight).asDouble; if (!equivalent(weight, 0.0)) { if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight) { if (weight > selectedWeight) { MObject mesh = targetElement.child(targetGeometry).asMesh; if (!mesh.isNull) { selectedMesh = mesh; selectedWeight = weight; } } } else { if (weight < selectedWeight) { MObject mesh = targetElement.child(targetGeometry).asMesh; if (!mesh.isNull) { selectedMesh = mesh; selectedWeight = weight; } } } } targetArray.next(); } // if (selectedMesh == null) { block.setClean(plug); } else { // The transform node via the geometry attribute will take care of // updating the location of the constrained geometry. MDataHandle outputConstraintGeometryHandle = block.outputValue(constraintGeometry); outputConstraintGeometryHandle.setMObject(selectedMesh); } } else { return(false); } return(true); }