I want to export my selected meshes in .obj in a relative path from the .blend file in python.


2 Answers 2


export obj to relative file path script:

import bpy
import os

blend_file_path = bpy.data.filepath
directory = os.path.dirname(blend_file_path)
target_file = os.path.join(directory, 'myfile.obj')


further export obj options:

bpy.ops.export_scene.obj(filepath="", check_existing=True, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl", use_selection=False, use_animation=False, use_mesh_modifiers=True, use_edges=True, use_smooth_groups=False, use_smooth_groups_bitflags=False, use_normals=True, use_uvs=True, use_materials=True, use_triangles=False, use_nurbs=False, use_vertex_groups=False, use_blen_objects=True, group_by_object=False, group_by_material=False, keep_vertex_order=False, global_scale=1, path_mode='AUTO')
  • $\begingroup$ Hi, thank you it works. And how can i export it in a relative subfolder and an absolute path? $\endgroup$ Jul 20, 2017 at 22:22
  • 1
    $\begingroup$ he script i gave you exports to the folder of the .blend file if you want to ad a subfolder you can just add it in this line: target_file = os.path.join(directory, 'subfolder', 'myfile.obj') An absolute path you can provide as a string bpy.ops.export_scene.obj(filepath="C:/path/to/file.obj") $\endgroup$ Jul 21, 2017 at 8:23
  • $\begingroup$ I don't undertand which line i should replace. I want the user to type the absolute or relative path in the same place, then after the path it adds 'lod0_' then it takes the mesh's + name name = 'game_asset' and add + '.obj'. $\endgroup$ Jul 22, 2017 at 12:02
  • $\begingroup$ export to directory subfolder dont work $\endgroup$
    – DB3D
    Apr 6, 2019 at 10:42

See if that helps you :

How to write a simple Wavefront-OBJ exporter in Python?

Or you can simply use the export button in blender :

enter image description here

And make sure "Selectio Only" is checked enter image description here


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.