#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def object_id(obj): return "object:" + obj.name def collection_id(collection): return "collection:" + collection.name def scene_report(): scene = bpy.context.scene obj = bpy.data.objects.get("WBV2P2001SelectedObject") collection = bpy.data.collections.get("WBV2P2001OutlinerCollection") if obj is None or collection is None: raise RuntimeError("EDITOR_OPEN_SCENE_INVALID: stable object or collection is missing") selected = sorted(object_id(value) for value in bpy.context.selected_objects) if bpy.context.view_layer.objects.active is not obj or selected != [object_id(obj)]: raise RuntimeError("EDITOR_OPEN_SCENE_INVALID: selection context drift") return { "scene": {"id": "scene:" + scene.name, "name": scene.name, "rootCollectionId": collection_id(scene.collection)}, "collection": { "id": collection_id(collection), "name": collection.name, "objectIds": sorted(object_id(value) for value in collection.objects), "childCollectionIds": sorted(collection_id(value) for value in collection.children), }, "selection": { "activeObjectId": object_id(obj), "selectedObjectIds": selected, "revision": 1, }, } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-wbv2-p2-001-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=True) before = scene_report() descriptor, temporary = tempfile.mkstemp(prefix="wbv2-p2-001-reopen-", suffix=".blend", dir=fixture.parent) os.close(descriptor) try: bpy.ops.wm.save_as_mainfile(filepath=temporary, check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=temporary, load_ui=True) after = scene_report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"EDITOR_OPEN_SCENE_INVALID: desktop save/reopen drift: {before} != {after}") value = { "schemaVersion": 1, "task": "WBV2-P2-001", "operation": "EDITOR_OPEN_SCENE_DESKTOP", "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "context": after, "missingData": {"pinnedData": None, "library": None}, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"wbv2-p2-001-desktop-ok scene={after['scene']['id']} active={after['selection']['activeObjectId']} saveReopen=exact") if __name__ == "__main__": main()