LumaPictures / pymel

Python in Maya Done Right
Other
490 stars 131 forks source link

AnimCurve is missing getTangent() #414

Open leocov-dev opened 6 years ago

leocov-dev commented 6 years ago

in 1.0.8 the AnimCurve class had a getTangent() method, in 1.0.10 it is gone. MFnAnimCurve still has the getTangentXY method, so not sure why this was omitted from pymel.

leocov-dev commented 6 years ago

also setTangent() is missing

pmolodo commented 5 years ago

Hmm... looks like the problem was that in 2018, the function signature for getTangent was changed so that it now has args of TangentValue type, where they used to be doubles:

http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_class_m_fn_anim_curve_html

Of course, TangentValue is just a typedef for a double, but currently pymel doesn't have anything for dealing with typedefs - so it just assumes it's a type it doesn't know how to deal with, and doesn't wrap it.

I'll take a look at how hard adding typedefs support would be...

RobinScher commented 5 years ago

Is there any update on this? It is affecting my company and blocking us from upgrading Maya at the moment. Thanks, -r

leocov-dev commented 5 years ago

I handled this as a monkey patch until an official solution is released.

import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as om2anim
import pymel.core as pm

def patch_anim_curve():
    """
    Maya 2018.3 pymel is missing getTangent() and setTangent() methods for some reason, but the API functions are still
    available, so we make our own and patch AnimCurve
    """
    if not hasattr(pm.nt.AnimCurve, "getTangent"):

        def getTangent(self, index, inTangent):

            sel_list = om2.MSelectionList()
            sel_list.add(self.longName())
            curve_mobject = sel_list.getDependNode(0)
            curve_fn = om2anim.MFnAnimCurve(curve_mobject)

            return curve_fn.getTangentXY(index, inTangent)

        pm.nt.AnimCurve.getTangent = getTangent

    if not hasattr(pm.nt.AnimCurve, "setTangent"):

        def setTangent(self, index, x, y, inTangent, change=None, convertUnits=True):

            sel_list = om2.MSelectionList()
            sel_list.add(self.longName())
            curve_mobject = sel_list.getDependNode(0)
            curve_fn = om2anim.MFnAnimCurve(curve_mobject)

            if not change:
                curve_fn.setTangent(index, x, y, inTangent, convertUnits=convertUnits)
            else:
                curve_fn.setTangent(index, x, y, inTangent, change=change, convertUnits=convertUnits)

        pm.nt.AnimCurve.setTangent = setTangent