Jump to content

[SOLVED] Blender - Batch Export using Babylon Exporter Addon ?


Recommended Posts


I recently wanted to try and use/adapt the official Blender exporter addon for Babylon to allow for parsing a directory of source models (FBX) and have Blender batch export them to the Babylon Json format. I know that there is a C++ CLI tool to do exactly this but (correct me if I'm wrong) it seems like it will only run on Windows (no OSX or Linux). So I wanted to be add this functionality via Python scripting in Blender to be able to do this no matter the platform. Disclaimer, Python is not my native language. :P

I taken some inspiration from a few existing scripts and adapted a simple one that :

  1. Looks for files ending with FBX in the input path.
  2. Imports them (one by one) via the Blender FBX operator :
  3. Exports them (one by one) via the BabylonJS operator :



Sadly here I am getting an error. Perhaps I'm being naive here by thinking that I can access a non-standard issue addon via scripting ? That is what the error seems to indicate at least :

Traceback (most recent call last):
  File "/BatchConvert.py", line 54, in <module>
  File "/BatchConvert.py", line 44, in convert_recursive
  File "/Users/ozeki/Library/Application Support/Steam/steamapps/common/Blender/blender.app/Contents/MacOS/../Resources/2.78/scripts/modules/bpy/ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
AttributeError: Calling operator "bpy.ops.bjs.main" error, could not be found

location: <unknown location>:-1


Solution ?

Is this doable with the way the Babylon Blender addon is setup and if so what am I doing wrong? I have attached my current code to this post. I've also added a list of references for the scripts that I have looked at or adapted from originally.




Link to comment
Share on other sites

This has no been tried up till now.  I am not hopeful.  First, I assume exporter is permanently saved as enabled.

I also tried calling a MakeHuman add-in from my code.  I remember having to add it onto my "path".  I do not do it anymore, but I remembered on the MakeHuman forum I pasted code which did.  You will have to convert this for us:

# add import_runtime_mhx2 to sys.path, so can be imported
mhxOnPath = False
def putMhxOnPath():
    global mhxOnPath
    if not mhxOnPath:
        import os
        import sys
        addon_paths = bpy.utils.script_paths('addons')
        for path in addon_paths:
            lib_path = os.path.join(path, 'import_runtime_mhx2')
            if os.path.exists(lib_path):
                print('mhx2 found @ ' + lib_path)
                mhxOnPath = True
    return mhxOnPath

Finally, the exporter will bring up UI, something called exporthelper.  Do not know if you can set filepath like that.

Link to comment
Share on other sites

Hey again,

Thanks for your input, the path was a good clue to keep me going and helped me solve the problem. I was able to make this work with the 4.6.1 version of the Babylon Export as it exposes the bpy.ops.scene.babylon Blender Operator when you import io_export_babylon of that version of the Exporter.

I might try to make this work with the newer version later on but I don't have a lot of time right now. I'm willing to share my findings but fair warning, this hasn't been thoroughly tested so use it at your own risks. That being said when we solve a problem in an open-source community it is the least we can do to give something back so here is my contribution. Blender version and usage information is available in the file's header.

One could easily adapt this script to also have an OUTPUT_DIR next to the CONVERT_DIR in order to allow for outputting the files elsewhere than in the same folder but it did not bother me for my workflow. I believe one could also adapt this for use with almost any other two formats compatible with Blender. Either way cheers and thank you again!

Blender - Batch Export from Fbx to BabylonJS

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...