我有3个函数可以生成三个不同的列表。我正在尝试生成一个mel脚本,这是一个文本文件,它将写入从这三个列表中获取的值。所有三个列表都具有相同数量的值。这些列表中的所有值都是动画数据,因此必须在mel脚本中传递它们以在Maya中驱动动画。所有这些列表值都是浮点数。
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"};
........
........
文件中的前6行是默认行。 mel脚本中的文本应该一直持续到每个列表的最后一个值。我怎样才能做到这一点?谢谢。
答案 0 :(得分:1)
使用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)
添加您要生成的所有其他样板,并尝试考虑比x
,y
,z
更好的变量名称。