2018-10-11

Maya API ramp attribute bug?

1. When saving:

2. What gets stored in the ascii file: 
setAttr -s 2 ".falloff[1]"  1 1 1;

3. After opening the scene again:

I recently noticed in Maya 2018 that custom Python API 1.0 node ramp attribute elements with position/value/interpolation : 0.0/0.0/linear do not get saved with the Maya scene (if their index is the lowest). I guess this is a bug. Some debug infos I gathered:
  • Probably bug source: By default Maya does not save attribute default values
  • Does not happen with default Maya nodes like remapValue
  • MPxNode.shouldSave documentation explains why this should not happen (but it is not true): "This method is not called for ramp attributes since they should always be written."
  • Since shouldSave gets wrongfully called it has to be overwritten to fix the problem
  • Only returning 'unknown' will not save the attribute. OpenMayaMPx.MPxNode.shouldSave(...) does exactly that.
  • The Python devkit example of shouldSave pyApiMeshShape.py is a bit misleading: From what I have tested all these return values seem to force save: True, False, None 

Implementations of this workaround can be found in prClosestPoint:
https://github.com/parzival-roethlein/prmaya

Update 2020-03-31:
Another situation with the same problem was with a float array attribute in Python API 2.0. The fix is in my /plugins/prUpCurveSpline.py
https://github.com/parzival-roethlein/prmaya

1 comment:

  1. I've just run into this same issue and your post helped me to solve it. On the C++ side, you have to update the "result" parameter which is passed by reference. I wonder if technically you are supposed to do the same in python via MScriptUtil.

    ReplyDelete