0
$\begingroup$

I would like to import an obj file and export it as an fbx file without having to use the Blender GUI.

The command: blender --background --python myscript.py Is not working for me from Terminal on mac. My first real problem is I'd like to be able to do anything (even open blender using .exe) using Terminal. I've tried including the path to the Blender app but nothing seems to be working and I am just given the error "blender is not a command"

$\endgroup$
1

2 Answers 2

0
$\begingroup$

The link @HikariTw should give you an answer; for example on my system the path to Blender is /Applications/Blender.app/Contents/MacOS/Blender. The error you're getting is because the Blender binary isn't in your path.

As for importing/exporting; your script should be pretty simple, just remove the default cube, call bpy.ops.import_mesh.stl to import and bpy.ops.export_scene.fbx to export.

$\endgroup$
1
  • $\begingroup$ thank you! I will post my solution below $\endgroup$ Aug 27, 2020 at 15:59
0
$\begingroup$

I wanted to import an obj and export it as an fbx all from the Terminal without using the Blender GUI. The following answer helped me a lot.

My file was as follows:

import bpy
import sys

argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"

obj_in = argv[0]
fbx_out = argv[1]

bpy.ops.import_scene.obj(filepath=obj_in, axis_forward='-Z', axis_up='Y')
bpy.ops.export_scene.fbx(filepath=fbx_out, axis_forward='-Z', axis_up='Y')

I named the file BlenderConvertObjFbx.py and ran the script from within the MacOS folder as follows:

 ./blender --background --python BlenderConvertObjFbx.py -- foot.obj foot.fbx

foot.obj was the existing file and I also had it in the same MacOS folder. foot.fbx was generated by the script.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .