How to create an import button that loads always the same OBJ file?

I'm creating a connection bridge between Blender and other software. I was able to create a button following the scripts templates. In Blender, there is an import script template but contains a custom import function that prints text into the console.

This script is working but when I introduce the path, (filepath="X:/DoNotMove/Blender/mesh.obj") it stops working.

import bpy

# WIP BLENDER BRIDGE: Alan Mattano 2020 Soaring Stars lab

class CustomImpotPanle(bpy.types.Panel):
    """Import Custom Panel for Rhino bridge"""
    ui_tabTitle ="Import OBJ"
    ui_topHeader = "Blender Bridge"    

    bl_label = ui_tabTitle
    bl_idname = "OBJECT_PT_rhino"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout    
        obj = context.object

        row = layout.row()            
        row.label(text="Bridge", icon='MESH_CYLINDER')            

        # IMPORT OBJ (consider using %Temp%)
        row = layout.row()            
        row.operator("import_scene.obj", text="IMPORT OBJ", filepath="X:/DoNotMove/Blender/mesh.obj")

def register():

def unregister():

if __name__ == "__main__":

NOTE: By the way, the place for this type of button is not the best solution (but is working). Probably the top windows toolbar is a better solution.

  • 1
    $\begingroup$ For operators in layout, this exposes propertis op = row.operator("import_scene.obj") and set with op.filepath = "/foo/bar.obj" $\endgroup$ – batFINGER Jan 4 '20 at 15:35
  • $\begingroup$ Suggest looking in the system console for errors. The draw method above will be spitting out a zillion errors that UILayout.operator has no keyword argument filepath $\endgroup$ – batFINGER Jan 8 '20 at 0:10
  • $\begingroup$ The way to go is to create a second class. And use the operator to call it: row.operator("myops.import_obj", text="IMPORT MESH") $\endgroup$ – Alan Mattano Jan 8 '20 at 4:04
  • $\begingroup$ Yes could do that. But it's overkill registering a new operator per import file, where you can simply pass the filepath as shown. So IMO it's not the way to go. $\endgroup$ – batFINGER Jan 8 '20 at 4:12