3
$\begingroup$

I'm trying to create an action for the add menu in the video sequencer. I need it to open a file browser so the user can select a file to add. To do this I use ImportHelper, which works great if I trigger my action from the menu at the bottom of the Video Sequence Editor window. However, if I type ShiftA and then select the same action from the menu that pops up, the file browser doesn't show up. Is this a bug in Blender, or am I just missing something?

Here's a slightly modified version of the operator_file_import python template that exhibits this behavior:

import bpy
from bpy_extras.io_utils import ImportHelper
from bpy.types import Operator

class ImportSomeData(Operator, ImportHelper):
    """This appears in the tooltip of the operator and in the generated docs"""
    bl_idname = "sequencer.some_data"
    bl_label = "Import Some Data"

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


# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")


def register():
    bpy.utils.register_class(ImportSomeData)
    bpy.types.SEQUENCER_MT_add.append(menu_func_import)


def unregister():
    bpy.utils.unregister_class(ImportSomeData)
    bpy.types.SEQUENCER_MT_add.remove(menu_func_import)


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

By looking at the add menu defined in space_sequencer.py it sets layout.operator_context = 'INVOKE_REGION_WIN', this doesn't appear to carry into your menu item.

By setting the operator_context within your menu item method, the sample you provide would appear to work as you expect.

def menu_func_import(self, context):
    self.layout.operator_context = 'INVOKE_REGION_WIN'
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
$\endgroup$
  • $\begingroup$ Thank you so much! None of the examples I was looking at had that. Works like a charm now! $\endgroup$ – scribblemaniac Jan 1 '16 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.