Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blender Property not Updating While Needed (Python)

I am attempting to set a Property using the Blender Python API and add it to a RotationSyncFinalValue List. The List is set in the way it needs to be, but the Property is not Updating so the list is not showing the value.

Here's the code where I define the Property:

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

Here is where I set The property in the Panel:

layout = self.layout
scene = bpy.context.scene
col.prop(scene,"RotationSyncValuesList")
col = layout.column(align=True)

And this is my attempt to add a value to the array RotationSyncFinalValue

fvalue = ('{0:.4f}'.format(value),
'{0:.4f}'.format(value),
'{0:.4f}'.format(value))
RotationSyncFinalValue.extend([fvalue])
like image 965
FG tv Avatar asked Jun 15 '26 01:06

FG tv


1 Answers

Your using the wrong type for the task. An EnumProperty is a single value that must exist in a defined list of acceptable values, the list of items you pass to the constructor is a list of values that are acceptable to the property, values not in the initial list can not be assigned to the property.

I expect you want to look at the example given for CollectionProperty to end up with something like -

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

Then in your panel you could use -

for p in scene.RotationSyncValuesList:
    row = col.row()
    row.prop(p, 'x')
    row.prop(p, 'y')
    row.prop(p, 'z')

As you appear to want three properties with the same value, you should look at using custom get/set functions, this could ensure that all three properties stay in sync (or only store one value), you would add the get/set to the properties in the PropertyGroup class.

like image 172
sambler Avatar answered Jun 16 '26 14:06

sambler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!