2
$\begingroup$

I have a custom operator called collection.vary_collection that has an IntProperty called color_step. I managed to create a UI button calling the operator and I would like to add a slider that changes that property but I don't know what is the proper way to do that. So far I have just a slider but it doesn't respond :

enter image description here

This is my draw function :

def draw(self, context):
    props= self.layout.operator(
        'collection.vary_collection',
        text= 'Make Variants',
        icon= 'OUTLINER_OB_GROUP_INSTANCE'
    );
    self.layout.prop(props, 'color_step');

Can anyone help me with that or at least link me to some similar working examples?

$\endgroup$

1 Answer 1

2
$\begingroup$

Operators usually have their properties available in Adjust Last operator panel (F9) so if an operator has some property and has 'REGISTER' and 'UNDO' options:

enter image description here

it will show up in the panel after being used:

enter image description here

That's sort of standard way of doing things in Blender, but if you needed to have some property set before the operator is executed, you need to store it somewhere. If I understand it correctly, one common way to store global properties is in WindowManager:

import bpy

bpy.types.WindowManager.int_p = bpy.props.IntProperty(name = "Some Name", default=15)

class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    
    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row.prop(context.window_manager, "int_p")
        row.operator("mesh.primitive_cylinder_add").vertices = context.window_manager.int_p

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


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)


if __name__ == "__main__":
    register()

And here is the link with all the parameters available for integer properties

$\endgroup$
1
  • $\begingroup$ Thank you. My operator has already an UNDO support and all it was missing was that option to set the parameters before execution. Thank you so much! $\endgroup$ Commented Oct 31, 2022 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .