MStatus geometrySurfaceConstraintCommand::connectObjectAndConstraint( MDGModifier& modifier ) { MObject transform = transformObject(); if ( transform.isNull() ) { MGlobal::displayError("Failed to get transformObject()"); return MS::kFailure; } MStatus status; MFnTransform transformFn( transform ); MVector translate = transformFn.getTranslation(MSpace::kTransform,&status); if (!status) { status.perror(" transformFn.getTranslation"); return status;} MPlug translatePlug = transformFn.findPlug( "translate", &status ); if (!status) { status.perror(" transformFn.findPlug"); return status;} if ( MPlug::kFreeToChange == translatePlug.isFreeToChange() ) { MFnNumericData nd; MObject translateData = nd.create( MFnNumericData::k3Double, &status ); status = nd.setData3Double( translate.x,translate.y,translate.z); if (!status) { status.perror("nd.setData3Double"); return status;} status = modifier.newPlugValue( translatePlug, translateData ); if (!status) { status.perror("modifier.newPlugValue"); return status;} status = connectObjectAttribute( MPxTransform::geometry, geometrySurfaceConstraint::constraintGeometry, false ); if (!status) { status.perror("connectObjectAttribute"); return status;} } status = connectObjectAttribute( MPxTransform::parentInverseMatrix, geometrySurfaceConstraint::constraintParentInverseMatrix, true, true ); if (!status) { status.perror("connectObjectAttribute"); return status;} return MS::kSuccess; }
//- This method is plugToManipConversionCallback function //- You implement it so that a specific component of the manipulator //- will be modified automatically when some plug value changes on //- the custom locator. //- Arguments: //- manipIndex - the index of the component on the manip you want to affect, //- in this case, it is the center point of this manip //- Return Values: //- MManipData object, which represents the updated value MManipData arrowLocatorManip::centerPointCallback(unsigned int manipIndex) { MStatus status; //Get parent transform node of the locator node MObject parentTransform = fNodePath.transform(&status); //Get the transform node DAG path MDagPath transformPath; MDagPath::getAPathTo(parentTransform,transformPath); //Retrieve world space translation MFnTransform fnTrans(transformPath,&status); MVector translation = fnTrans.getTranslation(MSpace::kWorld,&status); MFnNumericData numData; MObject numDataValue = numData.create(MFnNumericData::k3Double,&status); status = numData.setData3Double(translation.x,translation.y,translation.z); MManipData manipData(numDataValue); return manipData; }