3
$\begingroup$

Let's say I want to create UI for addon which allows to choose options (eg delete meshes only) before script execution. How can I achieve that? I know about F6 panel (and options in the T-panel) but it works only after I run a script.

UI mockup

$\endgroup$
1
  • $\begingroup$ You can use an operator with a dialog, as explained in the docs. $\endgroup$ Jan 19, 2014 at 14:52

1 Answer 1

3
$\begingroup$

You can also register properties on bpy.types such as WindowManager, Scene etc., add them to a panel together with an operator (will appear as button) and pass the value of a global property (bpy.types) to the operator as operator property:

import bpy

class PrintSomeString(bpy.types.Operator):
    bl_label = "Print Some String"
    bl_idname = "object.print_some_string"
    bl_options = {'REGISTER', 'UNDO'}

    print_this = bpy.props.StringProperty(name="Print this")

    def execute(self, context):
        self.report({'INFO'}, self.print_this)
        return {'FINISHED'}


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        layout.prop(context.window_manager, "some_string")

        props = layout.operator(PrintSomeString.bl_idname)
        props.print_this = context.window_manager.some_string

        props = layout.operator(PrintSomeString.bl_idname, text="Print welcome message")
        props.print_this = "Welcome to Blender!"

def register():
    bpy.utils.register_module(__name__)
    bpy.types.WindowManager.some_string = bpy.props.StringProperty(name="Some String")


def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.WindowManager.some_string


if __name__ == "__main__":
    register()

(Adds a panel to the Object tab in Properties Editor)

$\endgroup$

You must log in to answer this question.

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