需要时Blender属性不更新(Python)

2024-09-29 23:31:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用Blender Python API设置一个属性,并将其添加到RotationSyncFinalValue列表列表按需要的方式设置,但属性未更新,因此列表不显示值。在

下面是我定义属性的代码:

atr = bpy.types.Scene
RotationSyncFinalValue = []
atr.RotationSyncValuesList =EnumProperty(
items= RotationSyncFinalValue,
name = "List", 
description = "Select The Action to Do with the Value")

下面是我在面板中设置属性的位置:

^{pr2}$

这是我试图给数组添加一个值RotationSyncFinalValue

fvalue = ('{0:.4f}'.format(value),
'{0:.4f}'.format(value),
'{0:.4f}'.format(value))
RotationSyncFinalValue.extend([fvalue])

Tags: 代码apiformat列表属性定义value方式
2条回答

你在任务中使用了错误的类型。EnumProperty是必须存在于已定义的可接受值列表中的单个值,传递给构造函数的项列表是该属性可接受的值的列表,不在初始列表中的值不能分配给该属性。在

我希望您能看看给CollectionProperty提供的示例,以得到类似于-

class RotationSyncValuesType(bpy.types.PropertyGroup):
    x = bpy.props.FloatProperty(name='x', default=0.0)
    y = bpy.props.FloatProperty(name='y', default=0.0)
    z = bpy.props.FloatProperty(name='z', default=0.0)

bpy.utils.register_class(RotationSyncValuesType)
bpy.types.Scene.RotationSyncValuesList = \
        bpy.props.CollectionProperty(type=RotationSyncValuesType)

fvalue = bpy.context.scene.RotationSyncValuesList.add()
fvalue.x = 1.0
fvalue.y = 1.0
fvalue.z = 1.0

fvalue = bpy.context.scene.RotationSyncValuesList.add()
fvalue.x = 2.0
fvalue.y = 2.0
fvalue.z = 2.0

那么在你的小组里你可以用-

^{pr2}$

由于您似乎想要三个具有相同值的属性,您应该考虑使用custom get/set functions,这可以确保所有三个属性保持同步(或者只存储一个值),您可以将get/set添加到PropertyGroup类中的属性。在

如果您使用的是前面提到的数组,那么您可以查看文档并理解不能使用数组对象将列表传递给此函数。在

array.extend(iterable) Append items from iterable to the end of the array. If iterable is another array, it must have exactly the same type code; if not, TypeError will be raised. If iterable is not an array, it must be iterable and its elements must be the right type to be appended to the array. https://docs.python.org/2/library/array.html

如果是打字错误,RotationSyncFinalValue是一个列表,请添加更多信息,以便我们可以帮助您。在

相关问题 更多 >

    热门问题