#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def action_channels(action): channels = [] for layer in action.layers: for strip in layer.strips: for bag in strip.channelbags: for curve in bag.fcurves: channels.append({ "path": curve.data_path, "index": curve.array_index, "frames": [round(float(keyframe.co.x), 6) for keyframe in curve.keyframe_points], }) channels.sort(key=lambda value: (value["path"], value["index"])) return channels def action_report(): obj = bpy.data.objects.get("WebGapActionUnlinkObject") if obj is None or obj.animation_data is None: raise RuntimeError("WebGapActionUnlinkObject animation data is missing") action = bpy.data.actions.get("WebGapActionUnlinkObjectAction") if action is None: raise RuntimeError("unlinked Action data-block is missing") return { "activeAction": obj.animation_data.action.name if obj.animation_data.action else None, "unlinkedAction": { "name": action.name, "users": action.users, "useFakeUser": action.use_fake_user, "channels": action_channels(action), }, } def main(): arguments = sys.argv[sys.argv.index("--") + 1:] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-action-unlink-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False) before = action_report() if before["activeAction"] is not None or before["unlinkedAction"]["users"] != 1 or not before["unlinkedAction"]["useFakeUser"]: raise RuntimeError(f"unexpected action.unlink result: {before}") descriptor, temporary = tempfile.mkstemp(prefix="m16-action-unlink-reopen-", suffix=".blend") 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=False) after = action_report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"action.unlink save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "M16-GAP-00146", "operation": "ACTION_UNLINK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "action": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8") print("action-unlink-desktop-ok activeAction=none fakeUser=true saveReopen=exact") if __name__ == "__main__": main()