"""Read canonical object/scene Main state from Chromium-saved blend artifacts.""" import json import pathlib import sys import bpy directory = pathlib.Path(sys.argv[sys.argv.index("--") + 1]) snapshots = {} for blend in sorted(directory.glob("*.blend")): bpy.ops.wm.open_mainfile(filepath=str(blend), load_ui=False) # Names bind ID references without serializing process-specific addresses. snapshots[blend.stem] = { "objects": [ { "name": obj.name, "type": obj.type, "data": obj.data.name if obj.data else None, "parent": obj.parent.name if obj.parent else None, "matrix": [list(row) for row in obj.matrix_world], "collections": sorted(collection.name for collection in obj.users_collection), } for obj in sorted(bpy.data.objects, key=lambda item: item.name) ], "scenes": [ { "name": scene.name, "frame": scene.frame_current, "objects": sorted(obj.name for obj in scene.objects), } for scene in sorted(bpy.data.scenes, key=lambda item: item.name) ], } (directory / "native-main-snapshots.json").write_text( json.dumps(snapshots, sort_keys=True, separators=(",", ":")), encoding="utf-8" )