搅拌器比例值不更新

时间:2016-06-01 20:49:19

标签: python audio blender

当我运行此脚本时:

import bpy
import math

s = bpy.context.scene.frame_start 
e = bpy.context.scene.frame_end

values = []
print(s)
print(e)

for i in range(s,e):
    bpy.context.scene.frame_current = i
    print(i)
    v = (bpy.context.object.scale[1])
    bpy.context.object.scale[0] = i
    print('At frame ',str(i), ' value ' ,str(v))
    values.extend([bpy.context.object.scale[1]])

它给了我正确的帧数,但是值总是相同的,即使对象的比例[1]被烘焙成声音,所以它总是在帧之间改变。

看起来Blender不会更新值,它总是在文本运行期间获取帧的值。

如何在实时运行代码期间更新值?

1 个答案:

答案 0 :(得分:1)

您正在查看错误的值。

您有v = scale[1]然后设置scale[0] = i然后设置print(v)所以您的阅读比例。并且更改scale.x然后查看scale.y

最好使用scene.frame_set()通过python更改帧。

获取键控值的另一种方法是使用fcurve.evaluate(frame)

import bpy

s = bpy.context.scene.frame_start 
e = bpy.context.scene.frame_end

values = []
f = bpy.context.object.animation_data.action.fcurves.find('scale', index=1)

for i in range(s,e):
    v = f.evaluate(i)
    print('At frame ',str(i), ' value ' ,str(v))
    values.extend([v])

如果您计划对值进行关键帧设置,则不需要更改帧,因为您可以在keyframe_insert(data_path, frame=f)中指定帧

obj.keyframe_insert('scale', frame=2)
obj.keyframe_insert('scale', index=1, frame=5) # key only scale.y