Dirtying a Maya MPlug for Array Attribute

In Maya API, there is no way to explicitly set a plug dirty. However there is a MEL command "dgdirty()" to do exactly that. The MEL command takes the plug name and optionally the index if the plug is an array. I.e. 'dgdirty myNode.myattribute[1]'. In this example you set dirty the second element of your array plug.

Node_connectionsThere is also a MEL command to determine is a plug is dirty or not – that command is simply named "isDirty()". From a Python or C++ you can use the MGlobal::executeCommand() to execute the above two MEL commands, while in Python you can also use the command directly since you can now mix command and API call within the same Python script.

However there is an issue we need to consider – In case plugs are array plugs, you may create what we call internally “fat connection”. A “fat connection” happens when connecting array plugs at the root level vs elements. And if the plugs are dynamic as well, there is no way of knowing how many children need to be connected until the evaluation is completed. This is a perfect scenario where "fat connection" are made. It is therefore impossible to dirty a single element with this type of connection because the connection doesn’t even know if that element exists, or even if that element will keep the same logical index on the next evaluation. Since the information required to connect the multi-element is only generated by an evaluation there is no way to do it automatically, …

Connection_broken

… you have to do it manually (and manage any changes in the size or indexes of the element in the output array).

Connections
Therefore, even if you explicitly call the "dgdirty()" command on individual element plug, it may only dirty the root plug. Since this command sends a dirty message to a “connected” plug only, and the i'th element plug has no connection itself, it will not dirty this element plug. Therefore the compute() function will not get triggered when the value of the element plug is requested. The compute() function will only be triggered when the root plug is requested.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading