0
$\begingroup$

Hi this is probably very simple but it is proving difficult to archive

I am basically atempting to make a button in the UI tools panel that can run any function I create

Example

def PrinterFunction() :
    print (' hi world')

How do I put this example function into a button in the UI tools panel

Thanks

$\endgroup$

1 Answer 1

1
$\begingroup$

bl_info = {
    "name": "",
    "description": "",
    "author": "",
    "blender": (2, 80, 0),
    "version": (0, 0),
    "category": "",
    "location": "3D View > UI > Create",
    "warning": "",
}

import boy

class PrinterFunction(bpy.types.Operator):
    """desc"""
    bl_idname = "print.helloworld"
    bl_label = "Hello World"
    bl_options = {'REGISTER', 'UNDO'}   
    def execute(self, context):
        print('hi world')
        return {'FINISHED'}


class OBJECT_PT_hw(bpy.types.Panel):
    bl_idname = "object_PT_hw"
    bl_label = "hw"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Create"
    bl_context = "objectmode"
    def draw(self, context):
        self.layout.use_property_split = True
        self.layout.operator('print.helloworld', icon="IMPORT", text="Rename here")

classes = (
    PrinterFunction,
    OBJECT_PT_hw,
)

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)

if __name__ == "__main__":
    register()

FYI: Blender already has many useful python templates. You can access them from here

enter image description here

$\endgroup$

You must log in to answer this question.

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