/*in the boolean flag case :
lets say aDistance and aAmount are both child of a compound in an array of 
compound*/
MStatus myclass::setDependentsDirty(const MPlug &plug, MPlugArray &affect)
{
                mayastream << "dirtying. .." << "\n";

        if(plug.isChild() && plug.attribute() == aDistance )
        {
                e_distance_change= true ;
                /*get index to target this attribute specifically will be
                useful with MArrayDataHandle*/
                m_element_idx = plug.parent().logicalIndex();
        }
        else
        if(plug.isChild() && plug.attribute() == aAmount )
        {
                
                e_amount_change= true ;
                /*get index to target this attribute specifically will be
                useful with MArrayDataHandle*/
                m_element_idx = plug.parent().logicalIndex();
        }

    return MPxNode::setDependentsDirty(plug , affect );
    
}
MStatus myclass::compute(...)
{
    //typical moves:
    cmp_array = datablock.inputArrayValue(aArray);
    if( e_distance_change == true )
    {
    /*    perform targeted calculations
            use cmp_array.jumpToElement(m_element_idx)*/
    }
    else
    if(e_amount_change == true )
    {
        /*perform targeted calculations
            use cmp_array.jumpToElement(m_element_idx)*/

    }
//...
}

/*in the use Plug case :
lets say aDistance and aAmount are both child of a compound in an array of 
compound*/
MStatus myclass::setDependentsDirty(const MPlug &plug, MPlugArray &affect)
{
                mayastream << "dirtying. .." << "\n";

        m_dirty_plug = plug;     
                /*just one line and we can use the plug however we want
                the benefit is we also have all the methods of MPlug
                like .isConnected and so on , aslong as the method stay ) const 
                we can use it in compute without a problem...
                we can use this to get index in array : 
                m_dirty_plug.parent().logicalIndex();
                now to compute() ... */

    return MPxNode::setDependentsDirty(plug , affect );
    
}
MStatus myclass::compute(...)
{
    //things I never saw:
    cmp_array = datablock.inputArrayValue(aArray);
    if(m_dirty_plug.isChild() && m_dirty_plug.attribute() == aDistance )  
    {
        /*perform targeted calculations
        use all the cool const methods of MPlug
        use cmp_array.jumpToElement(m_dirty_plug.parent().logicalIndex())*/
    }
    else
    if(m_dirty_plug.isChild() && m_dirty_plug.attribute() == aAmount)
    {
        /*perform targeted calculations
        use all the cool const methods of MPlug
        use cmp_array.jumpToElement(m_dirty_plug.parent().logicalIndex())*/

    }
    /*...
    optionnaly at the end you can if you want reset  m_dirty_plug with 
    m_dirty_plug.setMObject(MObject::kNullObj) but it's not really required 
because it
    will be reassigned ... it allow to use .isNull() in particular cases tho
    lot of things you can do with just a plug instead of 4 boolean flags, it's 
also 
    way easier to maintain*/
}


Sent from Mail for Windows 10

From: Marcus Ottosson
Sent: Saturday, March 17, 2018 12:01 PM
To: [email protected]
Subject: Re: [Maya-Python] Why most people use boolean flags instead ofcatching 
the MPlug ?

My question to you is, who is most people? Maybe if you share an example we 
could more easily spot why the decision to use a boolean was made for that 
particular case.

If I had to guess, then I'd think it's the same reason as to why it is ill 
advised to store a reference to an MObject; they aren't built to last. That is 
to say, storing an MObject, changing the Maya scenegraph, and later accessing 
the MObject could yield unexpected results, and in some cases even lead to 
crash, because the memory it points to is no longer what you think it is.

However if you know that there is no chance of the scenegraph to change for the 
duration of you storing this member variable, then I would think you should be 
fine. That is why I'm asking for examples, because odds are the examples you've 
have been unable to guarantee such conditions.
​
-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB9pPUBGsHk8_1Q53E4TTm42evbqtBrou6nLEXJmPH%3Dcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/5aad201a.06abdf0a.22219.1d0f%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to