Blender 属性 在需要时未更新 (Python)
Blender Property not Updating While Needed (Python)
我正在尝试使用 Blender Python API 设置 属性 并将其添加到 RotationSyncFinalValue List。 List 已按需要设置,但 属性 未更新,因此列表未显示值。
这是我定义 属性:
的代码
atr = bpy.types.Scene
RotationSyncFinalValue = []
atr.RotationSyncValuesList =EnumProperty(
items= RotationSyncFinalValue,
name = "List",
description = "Select The Action to Do with the Value")
这里是我在面板中设置属性的地方:
layout = self.layout
scene = bpy.context.scene
col.prop(scene,"RotationSyncValuesList")
col = layout.column(align=True)
这是我尝试向数组添加一个值 RotationSyncFinalValue
fvalue = ('{0:.4f}'.format(value),
'{0:.4f}'.format(value),
'{0:.4f}'.format(value))
RotationSyncFinalValue.extend([fvalue])
如果您像您提到的那样使用数组,那么您可以查看文档并了解不能使用数组对象将列表传递给此函数。
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 是一个列表,请添加更多信息以便我们为您提供帮助。
您为任务使用了错误的类型。 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
然后在你的面板中你可以使用 -
for p in scene.RotationSyncValuesList:
row = col.row()
row.prop(p, 'x')
row.prop(p, 'y')
row.prop(p, 'z')
由于您似乎想要三个具有相同值的属性,您应该考虑使用 custom get/set functions,这可以确保所有三个属性保持同步(或只存储一个值),您可以添加get/set 到 PropertyGroup class.
中的属性
我正在尝试使用 Blender Python API 设置 属性 并将其添加到 RotationSyncFinalValue List。 List 已按需要设置,但 属性 未更新,因此列表未显示值。
这是我定义 属性:
的代码atr = bpy.types.Scene
RotationSyncFinalValue = []
atr.RotationSyncValuesList =EnumProperty(
items= RotationSyncFinalValue,
name = "List",
description = "Select The Action to Do with the Value")
这里是我在面板中设置属性的地方:
layout = self.layout
scene = bpy.context.scene
col.prop(scene,"RotationSyncValuesList")
col = layout.column(align=True)
这是我尝试向数组添加一个值 RotationSyncFinalValue
fvalue = ('{0:.4f}'.format(value),
'{0:.4f}'.format(value),
'{0:.4f}'.format(value))
RotationSyncFinalValue.extend([fvalue])
如果您像您提到的那样使用数组,那么您可以查看文档并了解不能使用数组对象将列表传递给此函数。
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 是一个列表,请添加更多信息以便我们为您提供帮助。
您为任务使用了错误的类型。 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
然后在你的面板中你可以使用 -
for p in scene.RotationSyncValuesList:
row = col.row()
row.prop(p, 'x')
row.prop(p, 'y')
row.prop(p, 'z')
由于您似乎想要三个具有相同值的属性,您应该考虑使用 custom get/set functions,这可以确保所有三个属性保持同步(或只存储一个值),您可以添加get/set 到 PropertyGroup class.
中的属性