Setting an attribute value within an MPxConstraintCommand?

Setting an attribute value within an MPxConstraintCommand?

Anonymous
Not applicable
683 Views
2 Replies
Message 1 of 3

Setting an attribute value within an MPxConstraintCommand?

Anonymous
Not applicable

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; }
    }

    ...
}

 

0 Likes
684 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Assuming you're calling doIt() on your MDGModifier at some point, have you tried calling M3DView::refresh()? Sounds strange but it did solve few of my node creation/parenting/relationship issues in the past.

0 Likes
Message 3 of 3

naiqi.weng
Alumni
Alumni

This issue turns out to be a bug of current Maya implementation. A defect report has been submitted for this issue.

0 Likes