0

I am making the call to bpy.ops.export_scene.gltf(filepath=output_file, use_selection=True, export_format='GLTF_SEPARATE')

I tried the workaround here Script to export gltf fails with 'Context' object has no attribute 'active_object'

AttributeError: 'Context' object has no attribute 'active_object'

Passing the context to the gltf function looks to be deprecated and I don't see how to override the context using temp_override.

I assume I am not setting up the context correctly as I tried to export as fbx and also got an exception.

Anyone have any suggestions?

EDIT: Added a minimalistic script:

Clear the scene

#bpy.ops.wm.read_homefile(use_empty=True) #bpy.ops.wm.read_factory_settings(use_empty=True)

Load the GLTF file into an empty scene

bpy.ops.import_scene.gltf(filepath=GLTF_PATH)

out_path = utils.create_output_folder("xxxxx")

OUTPUT_FILE = out_path + "out.gltf" bpy.ops.export_scene.gltf(filepath=OUTPUT_FILE, use_selection=True, export_format='GLTF_SEPARATE')

If I include either of the lines to clear the scene I get the error. Wondering if there is a more correct way to clear Blender down to a state where it has no loaded data.

  • 1
    What Blender version are you using? Can you post a simple minimalistic script that reproduces the problem? – Harry McKenzie Apr 25 '23 at 08:07
  • I'm using Blender 3.5.0. I have since noticed that I don't get this error if I don't use either one of these lines at the start of my script (will update the question with minimalistic version): #bpy.ops.wm.read_homefile(use_empty=True) #bpy.ops.wm.read_factory_settings(use_empty=True) – babaandthepigman Apr 25 '23 at 10:55
  • I went with:
    def clear_scene():
        # Remove all objects
        bpy.ops.object.select_all(action='DESELECT')
        for obj in bpy.context.scene.objects:
            obj.select_set(True)
        bpy.ops.object.delete()
    
        # Remove all materials
        for mat in bpy.data.materials:
            bpy.data.materials.remove(mat)
    
        # Remove all textures from the data blocks
        for tex in bpy.data.textures:
            bpy.data.textures.remove(tex)
    
        # Remove all images from the data blocks
        for img in bpy.data.images:
            bpy.data.images.remove(img)
    
    – babaandthepigman May 03 '23 at 12:15

0 Answers0