Custom Operator.draw()

I’ve created a custom Panel and a custom Operator, and now I want to make the panel draw the Operator’s stuff using the custom Operator.draw(), but I seemingly got the thing wrong. What am I doing wrong?

Code follows:


<i>import </i>bpy

<i>class </i>RigListPanel(bpy.types.Panel):
    bl_label = "Rockhead Rigs"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Rockhead Rigs"
    bl_context = "objectmode"

    <i>def </i>draw(self, <i>context</i>):
        layout = self.layout
        layout.operator('wm.rockhead_riglist_update')

<i>class </i>OBJECT_OT_RigList_Update(bpy.types.Operator):
    '''Updates de rig list.'''

    bl_idname = "wm.rockhead_riglist_update"
    bl_label = "Update Rig List #"

    foo = bpy.props.FloatProperty()
    bar = bpy.props.BoolProperty()

    <i>def </i>draw(self, <i>context</i>):
        print('draw...')
        layout = self.layout
        layout = self.layout
        col = layout.column()
        col.label(text="Custom Interface!")
        col.prop(self, 'foo')
        col.prop(self, 'bar')

    <i>def </i>execute(self, <i>context</i>):
        print('execute...')
        <i>return </i>{'FINISHED'}

<i>def </i>RigList_Register():
    print("Registering 'PanelRigList'...")
    bpy.utils.register_class(RigListPanel)
    bpy.utils.register_class(OBJECT_OT_RigList_Update)


<i>def </i>RigList_Unregister():
    print("Unregistering 'PanelRigList'...")
    bpy.utils.unregister_class(RigListPanel)
    bpy.utils.unregister_class(OBJECT_OT_RigList_Update)

Change the RigList_Register/Unregister to just register and unregister, and paste this after everything:


if __name__ == "__main__":
    register()

Hello and thanks for the reply.
That’s not actually the problem, because I’m loading this module in a init.py file with the register()/unregister() handles calling these custom ones and working properly.
I’m able to create the panel and the operator does show and execute, but only as a simple button.

Only I can’t make the custom Operator.draw() method do it’s thing.

Oh, misunderstood the question. The operator draw doesn’t work like that, it’s for popup dialog and the operator options panel. You could just create props outside the operator, use those in the panels draw, and reference them in the operator.

Hi dandrea,
You must use the invoke() operator and ended with your execute() .


bl_info = {"name": "Test",
            "author": "AAA",
            "version": (1, 00),
            "blender": (2, 78, 0),
            "location": "BBB",
            "description": "CCC",
            "warning": "DDD",
            "wiki_url": "",
            "category": "TEST"}




import bpy
from bpy.types import Panel,  Operator

class RigListPanel(Panel):
    bl_label = "Rockhead Rigs"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Rockhead Rigs"
    bl_context = "objectmode"


    def draw(self, context):
        layout = self.layout
        layout.operator('wm.rockhead_riglist_update')



class OBJECT_OT_RigList_Update(Operator):
    '''Updates de rig list.'''
    bl_idname = "wm.rockhead_riglist_update"
    bl_label = "Update Rig List #"


    foo = bpy.props.FloatProperty()
    bar = bpy.props.BoolProperty()
    
    @classmethod
    def poll(cls, context):
        return True
    
    def check(self, context):
        return True
        
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width=240)
        
    def draw(self, context):
        print('draw...')
        layout = self.layout
        col = layout.column()
        col.label(text="Custom Interface!")
        col.prop(self, 'foo')
        col.prop(self, 'bar')


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


def register():
    print("Registering 'PanelRigList'...")
    bpy.utils.register_class(RigListPanel)
    bpy.utils.register_class(OBJECT_OT_RigList_Update)


def unregister():
    print("Unregistering 'PanelRigList'...")
    bpy.utils.unregister_class(RigListPanel)
    bpy.utils.unregister_class(OBJECT_OT_RigList_Update)


if __name__ == "__main__":
    register()


I completely misunderstood the rationale behind the Operator.draw().
Thank you so much for making it clear!