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():
bpy.utils.register_class(CustomImpotPanle)
def unregister():
bpy.utils.unregister_class(CustomImpotPanle)
if __name__ == "__main__":
register()
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.
op = row.operator("import_scene.obj")
and set withop.filepath = "/foo/bar.obj"
$\endgroup$UILayout.operator
has no keyword argumentfilepath
$\endgroup$row.operator("myops.import_obj", text="IMPORT MESH")
$\endgroup$