0
$\begingroup$

In bpy how would I make a button of the F6 operation? That way I can have a button to call a panel. I would just add it to the top of my panel.

$\endgroup$
1
  • 1
    $\begingroup$ Do you want your button to show the operator properties dialog or do you want to show a floating panel that you have filled in? $\endgroup$
    – sambler
    Commented Nov 24, 2015 at 6:49

2 Answers 2

2
$\begingroup$

If you mean the "redo last" operation, which I believe is the default key binding for this function, then you can use this: (note that you'll have to include bl_info and register and unregister functions as in the code snippet below )

import bpy

class redo_last_operator(bpy.types.Operator):
    bl_idname = "screen.redo_last_operator"
    bl_label = "redo last"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self,context):
        bpy.ops.screen.redo_last()
        return {'FINISHED'}

Please note that importing this as an add-on will only add the operator to Blender, not add a Button to any panel. You can do that yourself, however, by creating a panel for it or adding it to a Panel yourself. The following code will create a panel as well:

import bpy

bl_info = {
    "version": (1, 0),
    "blender": (2, 75, 0),
    "name": "Redo Last Operator",
    "description": """Creates an operator for the redo last menu""" ,
    "category": "File",
    "location": """""",
}

class redo_last_operator(bpy.types.Operator):
    # this class is meant only for destroying data blocks of a certain type, very powerful but very dangerous
    bl_idname = "screen.redo_last_operator"
    bl_label = "redo last"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self,context):
        bpy.ops.screen.redo_last()
        return {'FINISHED'}

class redo_last_operator_panel(bpy.types.Panel):
    bl_label="redo last"
    bl_idname="redo_last_operator"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category='Addons'

    def draw(self,context):
        self.layout.operator(redo_last_operator.bl_idname)

def register():
    bpy.utils.register_class(redo_last_operator)
    bpy.utils.register_class(redo_last_operator_panel)

def unregister():
    bpy.utils.unregister_class(redo_last_operator)
    bpy.utils.unregister_class(redo_last_operator_panel)

if __name__ == "__main__":
    register()

If, on the other hand, you meant another operation, you can use the same code and still bind it to the button by replacing the code under execute().

$\endgroup$
5
  • 1
    $\begingroup$ The issue with your script is it just runs an infinite loop, your operator's execute() is simply calling itself. You would need to use a different bl_idname for your operator, or you can just use the existing operator in your panel. Also don't add questions to your answer, If you are unsure of the persons question ask for more detail in the comments before answering. $\endgroup$
    – sambler
    Commented Nov 24, 2015 at 6:40
  • $\begingroup$ You're right that my script did run recursively, I changed my answer to reflect the fix. $\endgroup$
    – MaVCArt
    Commented Nov 24, 2015 at 10:22
  • $\begingroup$ well the thing is is that I have a library of operators that are being called but the panels have to come up with F6. Its there a way to call the options panel up automatically? $\endgroup$ Commented Nov 24, 2015 at 17:27
  • $\begingroup$ I don't fully understand which options panel you wish - I presume you're talking about the panel that appears when the "redo last" operator points to the creation of a new primitive or other type of parametric object? If so, you'll need to track down those specific operators, and call them within your own code. At least that's the only thing I can think of. $\endgroup$
    – MaVCArt
    Commented Nov 25, 2015 at 13:54
  • $\begingroup$ This does actually not call the redo.last interface. It seems to me as one cannot call it from inside a script. but a button can contain just operator("screen.redo_last"). $\endgroup$ Commented Jan 11, 2016 at 17:06
0
$\begingroup$

There seem to be an issue with calling the bpy.ops.screen.redo_last inside a custom command.

But you can simply create a button and let the button call screen.redo_last directly.

import bpy

bl_info = {
    "version": (1, 0),
    "blender": (2, 75, 0),
    "name": "Redo Last Operator",
    "description": """Creates an operator for the redo last menu""" ,
    "category": "File",
    "location": """""",
}



class redo_last_operator_panel(bpy.types.Panel):
    bl_label="redo last"
    bl_idname="redo_last_operator"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category='Addons'

    def draw(self,context):
        self.layout.operator("screen.redo_last")

def register():
    bpy.utils.register_class(redo_last_operator)
    bpy.utils.register_class(redo_last_operator_panel)

def unregister():
    bpy.utils.unregister_class(redo_last_operator)
    bpy.utils.unregister_class(redo_last_operator_panel)

if __name__ == "__main__":
    register()
$\endgroup$

You must log in to answer this question.

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