0

I have to create Blender tools which will open as separate window, and once done with the process, I close them explicitly, I was testing it with a sample tool here which opens as a separate window, the Python script for which is as follows:

import bpy

class MyCustomPanel(bpy.types.Panel): bl_idname = "OBJECT_PT_custom_panel" bl_label = "My Custom Panel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Custom Addon'

def draw(self, context):
    layout = self.layout
    row = layout.row()
    row.operator("object.my_operator")

class MyCustomOperator(bpy.types.Operator): bl_idname = "object.my_operator" bl_label = "My Custom Operator"

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

def invoke(self, context, event):
    return context.window_manager.invoke_props_dialog(self, width=200)

def draw(self, context):
    layout = self.layout
    layout.label(text="My Custom Operator")
    row = layout.row()
    row.operator("mesh.primitive_cube_add", text="Add Cube")
    row.operator("mesh.primitive_cone_add", text="Add Cone")

def register(): bpy.utils.register_class(MyCustomPanel) bpy.utils.register_class(MyCustomOperator)

def unregister(): bpy.utils.unregister_class(MyCustomPanel) bpy.utils.unregister_class(MyCustomOperator)

if name == "main": register()

But there is one issue with this one, as soon as I am clicking somewhere else the tool window is getting closed. What approach should I take such as I'll get a close button (X) in my tool window and it'll only close when I click on it; otherwise it stays open.

  • Hello ! AFAIK you can't do that, it would go against the design of Blender which forbids having areas stacked on top of one another. What you want I think is to use the operator redo panel which you can open with F9 once the operator has been executed. You would need to add bl_options = {"REGISTER", "UNDO"} to the operator class definition. I think your original design is flawed, it is not supported to call an operator inside another operator's props popup. Even if it is technically possible to do so, it will lead to undefined behavior. You should maybe consider using a subpanel to do this – Gorgious May 09 '23 at 12:15
  • You can also explore pie menus which let you display submenus in the 3D viewport interface – Gorgious May 09 '23 at 12:17
  • @Gorgious Ah thanks for your response , just one more thing is it also not possible using external libraries like PyQt and then creating a UI using it, or it will still fall under the undefined behaviour like you mentioned? – madara_was_right May 09 '23 at 12:31
  • It is indeed possible but it will require a fair bit of jumps through hoops. see https://www.youtube.com/watch?v=QYgHyi7jd9c or https://blender.stackexchange.com/questions/43899/how-to-import-pyqt-into-blender The main difficulty I think is to be able to interact between Blender's logic loop and QT's interface loop – Gorgious May 09 '23 at 12:44
  • @Gorgious got it thanks alot – madara_was_right May 09 '23 at 12:51

0 Answers0