Okey. I am quite new to scripting in Maya but I try to make the best out of my limited knowledge.
I have a textfile that we get from unity with ~162000 frames that I want to import into Maya as keyframes. And it has worked great when it is files with around 50000 frames but when it increases the program it seems to use up all the memory So I would say that there is where the problem is. I have searched on google and found that I could use openMaya and use the api instead of cmds. But I have not been able to get it to work.
import maya.cmds as cmds
with open("C:\Textfiles\FacialData_Doctor(Clone)2001_Peter_fps40_2017-08-02_14-04-28.txt", 'r') as f:
for line in f:
framecount, blendshape, name, x = line.strip(" \t\r\n[]").split(",")
objectName = cmds.ls(name[10:] + "_Driver")
#print(name)
#print(objectName)
print(framecount)
cmds.setKeyframe( objectName, time=int(framecount), attribute='translateX', value=float(x)/float(10)*float(3) )
print("Done")
f.close()
This is how i do it now. It is slow but it works. Except for the problem above.
The lines in the text document looks like this:
2,58.1543,FaceMorph.JawForward,0
where the lines are seperated with “,” first comes framecount then miliseconds then name of the blendshape and then we have the translate X.
we have 23 blendshapes per frame.
Hopefully I am able to express my problem.
Thank you!
162,000 frames is a lot (is that 90 minutes of animation?). On a heavy mesh I can see that being very taxing . It also looks like the object name is a list (since ls will return a list) – maybe it’s generating keys on unexpected objects? Does
Theodox:
I have created a number of controller objects in the scene(sliders) for each blendshape of the character(we have 23) so it is 162,000 frames * 23 so it might just be that my laptop can’t handle the load.
The reason I am doing the ls is to select the corresponding controller to that blendhsape and in this case our mesh had a naming convention of facemorph.(blendshapename) and that is why I needed to remove the (facemorph.) bit to find the correct driver to add the keyframe to.
And regarding the math. What an embarrassing mistake! Thank you for pointing it out!
For others that might face the same problem. It was printing out the number to console that resulted in a much slower import and the freezing. Don’t know why I did not test that before coming here but yeah. Thank you R.White!