Discussion:
[Maya-Python] driven animation curves in OpenMaya
p***@iconcreativestudio.com
2018-08-21 20:25:24 UTC
Permalink
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)
--
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_maya+***@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.
Justin Israel
2018-08-21 21:23:34 UTC
Permalink
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
https://goo.gl/XNcYvT

Justin
Post by p***@iconcreativestudio.com
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()
in_values.append(float(x))
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)
--
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
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.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0AMwYrHJPULDGyb68YkcWy1ox3PutRRGUZsd1Ks6pn%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Paxton Gerrish
2018-08-21 22:00:30 UTC
Permalink
*facepalm*
Thanks man 👍
Post by Justin Israel
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
https://goo.gl/XNcYvT
Justin
Post by p***@iconcreativestudio.com
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()
in_values.append(float(x))
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)
--
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
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.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0AMwYrHJPULDGyb68YkcWy1ox3PutRRGUZsd1Ks6pn%3DQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0AMwYrHJPULDGyb68YkcWy1ox3PutRRGUZsd1Ks6pn%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACXadjdSR6URFpnv3D2aF9SM2btUUzufR9CVJ%3DkRFEQ%2B91Lxjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...