Reputation: 811
I have 3 functions which generate three different lists. I am trying to generate a mel script which is a text file which will write the values taken from these three lists. All three lists have same number of values. All the values in these lists are animation data and therefore they have to be passed in a mel script to drive an animation in Maya. All these lists values are floating point numbers.
func1() :
generates tlist
func2() :
generates list1
func3() :
generates list2
def mel_script() :
""" Generating the mel script with the animation information """
with open("mel.txt", "w") as melFile :
melFile.write(setKeyframe "blend_shape.lip_round";
setKeyframe "blend_shape.jaw_open";
currentTime 0 ;
setAttr "blend_shape.lip_round" 0;
setAttr "blend_shape.jaw_open" 0;
setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"};
currentTime (first value of tlist) ;
setAttr "blend_shape.lip_round" (first value of list1);
setAttr "blend_shape.jaw_open" (first value of list2);
setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"};
currentTime (second value of tlist) ;
setAttr "blend_shape.lip_round" (second value of list1);
setAttr "blend_shape.jaw_open" (second value of list2);
setKeyframe -breakdown 0 -hierarchy none -controlPoints 0 -shape 0 {"blend_shape"};
........
........
The first 6 lines in the file are default. The text in the mel script should continue up until the last values from each list. How can I achieve this? Thank you.
Upvotes: 0
Views: 103
Reputation: 363737
Use zip
.
for x, y, z in zip(func1(), func2(), func3()):
melFile.write("currentTime %f" % x)
melFile.write('setAttr "blend_shape.lip_round" %f' % y)
melFile.write('setAttr "blend_shape.jaw_open" %f' % z)
Add in all of the other boilerplate you want to generate, and try to think of better variable names than x
, y
, z
.
Upvotes: 1