I'm new to pythonAPI.
MEL and python's setKeyframe is really slow and my computer freezes.
There is a polygon mesh which has about 10000 vertices and each vertex moves.
I have found the sample code at Autodesk website.
http://download.autodesk.com/global/docs/maya2014/en\_us/index.html?url=files/GUID-8A96A8DB-FD6F-434F-A878-288DD84E99C7.htm,topicNumber=d30e815804
Creating keyframes for an animated curve
import maya.OpenMaya as om
import maya.OpenMayaAnim as oma
def addkeys(plugName, times, values, changeCache):
# Get the plug to be animated.
sel = om.MSelectionList()
sel.add(plugName)
plug = om.MPlug()
sel.getPlug(0, plug)
# Create the animCurve.
animfn = oma.MFnAnimCurve()
animCurve = animfn.create(plug, oma.MFnAnimCurve.kAnimCurveTL)
# Copy the times into an MTimeArray and the values into an MDoubleArray.
timeArray = om.MTimeArray()
valueArray = om.MDoubleArray()
for i in range(len(times)):
timeArray.append(om.MTime(times[i], om.MTime.uiUnit()))
valueArray.append(values[i])
# Add the keys to the animCurve.
animfn.addKeys(
timeArray,
valueArray,
oma.MFnAnimCurve.kTangentGlobal,
oma.MFnAnimCurve.kTangentGlobal,
False,
changeCache
)
The sample code:
addkeys('pCube1.tx', [1.0, 3.0, 5.0], [0.6, 1.2, 2.4], None)
works well but, I can't select vertex like the following.
addkeys('pCube1.vtx[0]', [1.0, 3.0, 5.0], [0.6, 1.2, 2.4], None)
Is there any way to do like it?
Many thanks.