0
$\begingroup$

I am trying to create a script that converts an OBJ file into an FBX file in Blender 2.78:

import sys
import bpy
from bpy.ops import *

importPath = sys.argv[0]
exportPath = sys.argv[1]

objFile = bpy.ops.import_scene.obj(filepath=importPath, 
                                   axis_forward='-Z', 
                                   axis_up='Y', 
                                   filter_glob="*.obj;*.mtl", 
                                   use_edges=True, 
                                   use_smooth_groups=True, 
                                   use_split_objects=True, 
                                   use_split_groups=True, 
                                   use_groups_as_vgroups=False, 
                                   use_image_search=True, 
                                   split_mode='ON', 
                                   global_clamp_size=0.0)

bpy.ops.export_scene.fbx(filepath=exportPath, 
                         check_existing=True, 
                         axis_forward='-Z', 
                         axis_up='Y', 
                         filter_glob="*.fbx", 
                         version='BIN7400', 
                         ui_tab='MAIN', 
                         use_selection=False, 
                         global_scale=1.0, 
                         apply_unit_scale=True, 
                         bake_space_transform=False, 
                         object_types={'ARMATURE', 'CAMERA', 'EMPTY', 'LAMP', 'MESH', 'OTHER'}, 
                         use_mesh_modifiers=True, 
                         use_mesh_modifiers_render=True, 
                         mesh_smooth_type='OFF', 
                         use_mesh_edges=False, 
                         use_tspace=False, 
                         use_custom_props=False, 
                         add_leaf_bones=True, 
                         primary_bone_axis='Y', 
                         secondary_bone_axis='X', 
                         use_armature_deform_only=False, 
                         armature_nodetype='NULL', 
                         bake_anim=True, 
                         bake_anim_use_all_bones=True, 
                         bake_anim_use_nla_strips=True, 
                         bake_anim_use_all_actions=True, 
                         bake_anim_force_startend_keying=True, 
                         bake_anim_step=1.0, 
                         bake_anim_simplify_factor=1.0, 
                         use_anim=True, 
                         use_anim_action_all=True, 
                         use_default_take=True, 
                         use_anim_optimize=True, 
                         anim_optimize_precision=6.0, 
                         path_mode='AUTO', 
                         embed_textures=False, 
                         batch_mode='OFF', 
                         use_batch_own_dir=True, 
                         use_metadata=True)

The script reads the OBJ file from the importPath directory and then converts and exports the converted file to the exportPath directory.

I execute the script like so (from the Blender install directory):

blender --background --python C:\Path\To\Script\script.py

However, I get the error FileNotFoundError: [Errno 2] No such file or directory: 'blender'

Here is the full stack trace:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\Path\To\Script\script.py", line 8, in <module>
    objFile = bpy.ops.import_scene.obj(filepath=importPath, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl", use_edges=True, use_smooth_groups=True, use_split_objects=True, use_split_groups=True, use_groups_as_vgroups=False, use_image_search=True, split_mode='ON', global_clamp_size=0.0)
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\modules\bpy\ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\io_scene_obj\__init__.py", line 147, in execute
    return import_obj.load(context, **keywords)
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\io_scene_obj\import_obj.py", line 945, in load
    float_func = get_float_func(filepath)
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\io_scene_obj\import_obj.py", line 866, in get_float_func
    file = open(filepath, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'blender'

What does this mean? How can I fix it?

$\endgroup$
4
  • 1
    $\begingroup$ You're reading in sys.args for the import and export paths, but not providing the paths when you run the script? It looks like you're reading the in the literal first argument which is 'blender', which is why the import/export fails as it obviously can't find the file 'blender'. Does this help: blender.stackexchange.com/questions/6817/… $\endgroup$ Aug 25, 2017 at 13:20
  • $\begingroup$ Yeah, that looks like that could be the issue. I'm working on it. $\endgroup$
    – ack
    Aug 25, 2017 at 13:32
  • $\begingroup$ @RayMairlot That was the issue; I've got the import working. However, I can't get the export working; it gives the error TypeError: Converting py args to operator properties: : keyword "use_mesh_modifiers_render" unrecognized. Do I need to pass the obj file to the export method, or does import store it in some global variable? I've copied the export method straight from the docs; Export Scene Operators $\endgroup$
    – ack
    Aug 25, 2017 at 13:52
  • $\begingroup$ Exporting works based on the selected object(s), but I think if you're having problems with that specific command you should probably ask a new separate question as we are now veering away from the initial question of getting py args to work. $\endgroup$ Aug 25, 2017 at 13:58

0

Browse other questions tagged .