driven animation curves in OpenMaya

214 views
Skip to first unread message

pax...@iconcreativestudio.com

unread,
Aug 21, 2018, 5:12:00 PM8/21/18
to Python Programming for Autodesk Maya
Hey Guys, I am a bit stuck trying to create driven (unitless) animCurves with OpenMaya

I am in maya 2017, using OpenMaya api 2.0

I am trying to use MFnAnimCurve to create multiple keyframes at the same time. this seems to work when using timed curve types (using MTimeArray as first argument) but it fails when using unitless curves and a MDoubleArray for the first argument.. Am I missing something? should i be using a different type for the first argument?



import maya.api.OpenMaya as om
import maya.api.OpenMayaAnim as oma

graph_modifier = om.MDGModifier()

m_object = om.MFnDependencyNode().create('transform', 'locator1')
node = om.MFnDependencyNode(m_object)

m_plug = node.findPlug(node.attribute('translateX'), True)
out_plug = node.findPlug(node.attribute('translateY'), True)


mfn_anim_curve = oma.MFnAnimCurve()
curve_type = mfn_anim_curve.unitlessAnimCurveTypeForPlug(m_plug)
#curve_type = mfn_anim_curve.timedAnimCurveTypeForPlug(m_plug)


anim_curve_m_object = oma.MFnAnimCurve().create(m_plug, animCurveType=curve_type)
anim_curve = oma.MFnAnimCurve(anim_curve_m_object)

in_plug = anim_curve.findPlug(anim_curve.attribute('input'), True)

graph_modifier.connect(out_plug, in_plug)
graph_modifier.doIt()


in_values = om.MDoubleArray()
out_values = om.MDoubleArray()
for x in range(5):
in_values.append(float(x))
for x in range(5):
out_values.append(float(x))

print in_values, out_values

anim_curve.addKey(1.0, 1.0)
anim_curve.addKey(2.0, 2.0)

#This Fails
anim_curve.addKeys(in_values, out_values)

Justin Israel

unread,
Aug 21, 2018, 5:23:51 PM8/21/18
to python_in...@googlegroups.com
The documentation for MFnAnimCurve.addKeys() does specify that it only works for kAnimCurveTA, kAnimCurveTL, and kAnimCurveTU. Whereas the type being returned by unitlessAnimCurveTypeForPlug() is kAnimCurveUL

Justin

--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4641c1ee-0ddd-445e-b22e-1719447d0336%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paxton Gerrish

unread,
Aug 21, 2018, 6:00:46 PM8/21/18
to python_in...@googlegroups.com
*facepalm* 
Thanks man 👍

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/Bq4YU5-d9EM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0AMwYrHJPULDGyb68YkcWy1ox3PutRRGUZsd1Ks6pn%3DQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages