0

嗨,我有一个正在编写的脚本,但它没有像我想要的那样运行这是我到目前为止所得到的

import bpy
def Key_Frame_Points(): #Gets the key-frame values as an array.

    fcurves = bpy.context.active_object.animation_data.action.fcurves

    for curve in fcurves:

        keyframePoints = fcurves[4].keyframe_points # selects Action channel's axis / attribute

        for keyframe in keyframePoints:

            print('KEY FRAME POINTS ARE  @T ',keyframe.co[0])         
            KEYFRAME_POINTS_ARRAY = keyframe.co[0]

    print(KEYFRAME_POINTS_ARRAY)

Key_Frame_Points()

当我运行它时,它会按照我的意愿打印出所选对象上的所有关键帧。但问题是我不能出于某种原因将值打印到变量中。如果您运行它并检查 System concole。它的行为很奇怪。就像它打印出关键帧对象的值一样。但是当我要求它以数组的形式获取这些值时,它只是打印出最后一帧。

这是它的简要外观

在此处输入图像描述

4

1 回答 1

0

我认为您想要做的是将每个添加keyframe.co[1]到一个数组中,这意味着您要使用它KEYFRAME_POINTS_ARRAY.append(keyframe.co[1])并且要使其正常工作,您需要将其定义为循环外的空数组KEYFRAME_POINTS_ARRAY = []

请注意,keyframe.co[0]是键控的帧,而keyframe.co[1]是该帧的键控值。

另外值得注意的是,您正在遍历 fcurves 但不使用每条曲线。

for curve in fcurves:
    keyframePoints = fcurves[4].keyframe_points

通过fcurves[4]在这里使用,您每次都在读取相同的曲线,您可能打算使用keyframePoints = curve.keyframe_points

所以我希望你想要 -

import bpy

def Key_Frame_Points(): #Gets the key-frame values as an array.
    KEYFRAME_POINTS_ARRAY = []
    fcurves = bpy.context.active_object.animation_data.action.fcurves

    for curve in fcurves:
        keyframePoints = curve.keyframe_points
        for keyframe in keyframePoints:
            print('KEY FRAME POINTS ARE frame:{} value:{}'.format(keyframe.co[0],keyframe.co[1]))
            KEYFRAME_POINTS_ARRAY.append(keyframe.co[1])
    return KEYFRAME_POINTS_ARRAY

print(Key_Frame_Points())

您可能也有兴趣fcurves.find(data_path)通过它的路径来查找特定曲线。

此外fcurve.evaluate(frame),它还会为您提供任何帧的曲线值,而不仅仅是键控值。

于 2016-01-12T03:15:40.827 回答