0
$\begingroup$

I have this script that works on Blender 3.1, to convert a directory with fbx files to glb. I'm trying to using it in Blender 3.2.2, but the scripting is failling with:

"AttributeError: 'NoneType' object has no attribute 'scene'"

This error happens on the line were the glb file is being exported. But I could not understand why, if its a missing parameters, or something that I need to set in the context

The script is bellow

CONVERT_DIR = "/DIR"

import os

def file_iter(path, ext):
    for dirpath, dirnames, filenames in os.walk(path):
        for filename in filenames:
            ext = os.path.splitext(filename)[1]
            if ext.lower().endswith(ext):
                yield os.path.join(dirpath, filename)

import bpy


def reset_blend():
    bpy.ops.wm.read_factory_settings(use_empty=True)

def convert_recursive(base_path):
    for filepath_src in file_iter(base_path, ".fbx"):
        filepath_dst = os.path.splitext(filepath_src)[0] + ".glb"

        print("Converting %r -> %r" % (filepath_src, filepath_dst))

        reset_blend()

        bpy.ops.import_scene.fbx(filepath=filepath_src)

        ctx = bpy.context.copy()
        
        ctx['active_object'] = None

        bpy.ops.export_scene.gltf(ctx,export_format="GLB",filepath=filepath_dst)


if __name__ == "__main__":
    convert_recursive(CONVERT_DIR)

The stacktrace:

/Text:32: DeprecationWarning: Passing in context overrides is deprecated in favor of Context.temp_override(..), calling "export_scene.gltf"
'/app/blender/3.2/python/lib/python3.10/site-packages/libextern_draco.so' exists, draco mesh compression is available
20:11:52 | INFO: Starting glTF 2.0 export
Traceback (most recent call last):
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/__init__.py", line 628, in execute
    return gltf2_blender_export.save(context, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 35, in save
    json, buffer = __export(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 52, in __export
    __gather_gltf(exporter, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 66, in __gather_gltf
    active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 30, in gather_gltf2
    scenes.append(__gather_scene(blender_scene, export_settings))
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 38, in wrapper_cached
    result = func(*args, **kwargs)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 54, in __gather_scene
    vtree.construct(blender_scene)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py", line 95, in construct
    bpy.context.window.scene = blender_scene
AttributeError: 'NoneType' object has no attribute 'scene'
Error: Python: Traceback (most recent call last):
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/__init__.py", line 628, in execute
    return gltf2_blender_export.save(context, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 35, in save
    json, buffer = __export(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 52, in __export
    __gather_gltf(exporter, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 66, in __gather_gltf
    active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 30, in gather_gltf2
    scenes.append(__gather_scene(blender_scene, export_settings))
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gatheError: Python: Traceback (most recent call last):
  File "/Text", line 36, in <module>
  File "/Text", line 32, in convert_recursive
  File "/app/blender/3.2/scripts/modules/bpy/ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Python: Traceback (most recent call last):
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/__init__.py", line 628, in execute
    return gltf2_blender_export.save(context, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 35, in save
    json, buffer = __export(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 52, in __export
    __gather_gltf(exporter, export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 66, in __gather_gltf
    active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 30, in gather_gltf2
    scenes.append(__gather_scene(blender_scene, export_settings))
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py", line 38, in wrapper_cached
    result = func(*args, **kwargs)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py", line 54, in __gather_scene
    vtree.construct(blender_scene)
  File "/app/blender/3.2/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py", line 95, in construct
    bpy.context.window.scene = blender_scene
AttributeError: 'NoneType' object has no attribute 'scene'
Location: /app/blender/3.2/scripts/modules/bpy/ops.py:113
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.