Message 1 of 3
Setting an attribute value within an MPxConstraintCommand?
Not applicable
11-12-2013
03:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on a custom constrait node & command, and like the pointConstraint - I want to compute and set the restTranslate attribute value on the constraint node when the command executed to connect the cosntraint and the object.
I've tried everything I can think of and cannot get the value to stick. My current approach is to find the restTranslate plug on the constraint node in the connectObjectAndConstraint method, and try to set the value with the DGModifier by calling modifer.newPlugValue(plug, value). This looks like it should work. There are no errors, but the final value on the attribute is not what it gets set to.
has anyone gotten this to work?
code snippet:
MStatus
MyConstraintCommand::connectObjectAndConstraint( MDGModifer &modifer )
{
...
// Get the rest state plug on the constraint node
MObject obj = constraintNode()->thisMObject();
MFnDependencyNode nodeFn(obj);
MPlug restTransPlug = nodeFn.findPlug(MyConstraint::restTranslate);
if ( restTransPlug.isNull() )
{
displayError("restTranslate plug is null.");
return MStatus::kFailure;
}
// Set the translate value on the plug through the DGModifier
for (int i = 0; i <3; i++)
{
status = modifier.newPlugValueDouble(restTransPlug.child(i), translate[i]);
if (!status) { status.perror("modifer.newPlugValueDouble"); return status; }
}
...
}