Blender property of operator

Hi guys,

I`m working on little plugin for my friend where he can do multi object operations which are not available in blender (removing vertex groups to all objects and so on…), and I’m stuck on property view and I can’t find my use case on internet so I’m here.

I have operator:

class EnableDisableAutoSmoothOperator(bpy.types.Operator):
    bl_idname = "david.enable_disable_autosmooth"
    bl_label = "Smooth control"
    bl_options = {'REGISTER', 'UNDO'}

    status:  bpy.props.BoolProperty(
        name="enable", default=True)

    smoothValue: bpy.props.FloatProperty(
        name="smooth", default=30, min=0.0, max=180, soft_min=0.0,
        soft_max=180, step=1
    )

and than I create panel with GUI for this operator:

 operator = layout.operator(
    'david.enable_disable_autosmooth', text=f"Enable smooth")

operator.status = True

layout.prop(operator, "smoothValue", text="Smooth",
            slider=True)

Clicking and everythin works, but slider for my smoothValue property is static and i can’t change value, I don’t understand what i have to do to make it work.
As you can see on image, dragging of this value starts scene selection.
image

you can’t change the value because the property isn’t “active” since the operator isn’t running. If all you want to do is set the autosmooth angle for a mesh, why not just pass in the mesh’s property directly rather than doing some kind of round-about method with an operator?

if context.active_object.type =='MESH':
    box.prop(context.active_object.data, 'auto_smooth_angle', slider=True)

Also layout.prop(context.active_object.data, 'use_auto_smooth', toggle=True) for toggling autosmooth directly ? No need to reinvent the wheel when you can re-draw UI elements :slight_smile:

Thanks for answer, but I’m in multi selection mode,… I have no active object I want to set to all, that is point of my plugin

Thats for multi objects operation, so uix use case of toggle button could be weird because half of selected object has attribute on true and half dont, this is easier to see, just disable / enable it

Alright, then you need to understand unless you store the properties somewhere else in the file (eg bpy.types.Scene) you can’t change these before clicking on the operator, because they’re not tied to this instance of the operator yet, because it doesn’t exist when this part of the layout is drawn.

You’ll need to use invoke. and then tweak your props in the popup :

You can change the operator draw method to layout the popup as you wish

BSE_88

import bpy


class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    
    status:  bpy.props.BoolProperty(
        name="enable", default=True)

    smoothValue: bpy.props.FloatProperty(
        name="smooth", default=30, min=0.0, max=180, soft_min=0.0,
        soft_max=180, step=1
    )
    
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

    def execute(self, context):
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


if __name__ == "__main__":
    register()
    bpy.ops.object.simple_operator("INVOKE_DEFAULT")
1 Like

Thanks for your help, this is what I was looking for, have a nice day.