Last active
January 22, 2025 21:26
-
-
Save scurest/5fc2e219db2c7e0c2099733ab0c005a0 to your computer and use it in GitHub Desktop.
POC for importing .dae into new Blenders without Collada support by shelling out to an older one with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy, os, subprocess, tempfile | |
# Path to a Blender that supports Collada import | |
old_blender_exe = 'blender-3.6.1' | |
def import_dae(filepath): | |
filepath = os.path.abspath(filepath) | |
with tempfile.TemporaryDirectory(prefix="dae-import-") as tmpdir: | |
temp_blend = os.path.join(tmpdir, "temp.blend") | |
subprocess.run( | |
[ | |
old_blender_exe, | |
"-b", | |
"--python-exit-code", "1", | |
"--python-expr", | |
"import bpy;bpy.ops.wm.read_homefile(use_empty=True)", | |
"--python-expr", | |
f"import bpy;bpy.ops.wm.collada_import(filepath={repr(filepath)})", | |
"--python-expr", | |
f"import bpy;bpy.ops.wm.save_as_mainfile(filepath={repr(temp_blend)})", | |
], | |
check=True, | |
) | |
with bpy.data.libraries.load(temp_blend, link=False) as (data_from, data_to): | |
data_to.objects = data_from.objects | |
for ob in data_to.objects: | |
if ob is not None: | |
bpy.context.scene.collection.objects.link(ob) | |
import_dae("my-example-model.dae") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment