# Set custom location for import/export helper

I have two buttons in my panel, one to import obj and one to import collada. I have two folders named 'obj_files' and 'collada_files' in two locations on my machine. I'm using importhelper, but I want when I press on the Import OBJ button, the obj_files folder will be the default path which shows up which is the location where I stored all the obj files in it instead of browsing for it, and the collada_files path when pressing the import collada button. I've tried

bpy.ops.import_scene.obj(filepath = '/Users/UserA/Temp/obj_files/')

I've also tried the below but still didn't work:

class ImportOBJ(Operator, ImportHelper):
"""Import OBJ"""
bl_idname = "io.importobj"
bl_label = "Import OBJ"

filename_ext = ".obj"
filter_glob = StringProperty(
default="*.obj",
options={'HIDDEN'},
maxlen=255,
)
filepath = bpy.props.StringProperty(
name="File Path",
description="File path used for importing the OBJ file",
maxlen= 1024,
default= "/Users/UserA/Temp/obj_files/")

def execute(self, context):
bpy.ops.import_scene.obj(filepath = self.properties.filepath)


My guess is you want the filebrowser to open at this location. My suggestion on this would be to set up default path properties in your addon preferences (if an addon).

class ImportDefaultPathsAddon(AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__

default_obj_path = StringProperty(subtype='DIR_PATH')

def draw(self, context):
layout = self.layout
layout.label(text="Import Paths")
layout.prop(self, "default_obj_path")


def draw(self, context):
user_preferences = context.user_preferences

layout = self.layout
op = layout.operator("import_scene.obj")



The user would need to set the paths when the addon is enabled.

PS I've looked at other methods of doing this, and can also suggest ditching the ImportHelper subclass altogether and write your own invoke and parameters.

• Thank you. So I can't put the default filebrowser path hardcoded? as I don't want the user to enter it himself. Could you explain the other methods please? – Tak May 11 '17 at 8:20

There are a couple of ways to do this, but as batFinger said, just ditch the ImporterHelper and write your own invoke. A simple way is to just set the file path in the invoke:

class ImportOBJ(Operator, ImportHelper):
"""Import OBJ"""
bl_idname = "io.importobj"
bl_label = "Import OBJ"

filename_ext = ".obj"
filter_glob = StringProperty(
default="*.obj",
options={'HIDDEN'},
maxlen=255,
)
filepath = bpy.props.StringProperty(
name="File Path",
description="File path used for importing the OBJ file",
maxlen= 1024)

def execute(self, context):
bpy.ops.import_scene.obj(filepath = self.properties.filepath)

def invoke(self, context, event):
self.filepath = "/Users/UserA/Temp/obj_files/"