So I need an operator (for creating a DECIMATE modifier in the selected object) that runs every time that the value input is changed and uses that value (for the Ratio of the modifier).
For now I've this alternative. The problem is that when the value is changed nothing happens until the operator button is clicked (see code below).
So basically I would like an interface in which just the value is shown and if its changed then the operator runs, changinge of the value of the decimate modifier.
import bpy
from bpy.props import (BoolProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
)
class MyProperties(bpy.types.PropertyGroup):
my_float : bpy.props.FloatProperty (name = "Decimate Radio", soft_min = 0, soft_max= 1)
class ADDONNAME_PT_main_panel(bpy.types.Panel):
bl_label= "Add-On"
bl_idname = "PT_TestPanel"
bl_space_type = 'VIEW_3D'
bl_region_type= 'UI'
bl_category= 'Add-On'
def draw(self,context):
layout = self.layout
scene= context.scene
mytool= scene.my_tool
i=0
for obj in bpy.context.selected_objects:
i =i+1
if i==1 :
layout.prop(mytool,"my_float")
row= layout.row()
row.operator("addonname.myop_operator_3")
class ADDONNAME_OT_my_op_3(bpy.types.Operator):
bl_label = "Operator"
bl_idname = "addonname.myop_operator_3"
def execute(self, context):
scene = context.scene
mytool= scene.my_tool
obj_1 = bpy.context.selected_objects[0]
mod = obj_1.modifiers.new("Decimate", 'DECIMATE')
mod.ratio=mytool.my_float
return {'FINISHED'}
classes = [ ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op_3, MyProperties]
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.Scene.my_tool = PointerProperty(type=MyProperties)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
del bpy.types.Scene.my_tool
if name == "main":
register()


https://blender.stackexchange.com/questions/255486/blender-python-propertygroup-update – Psyonic Sep 14 '22 at 13:22