#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy OBJECTS = ("WebGapAnimMoveSlotA", "WebGapAnimMoveSlotB") OLD_ACTION = "WebGapAnimMoveSlotAction" def action_report(obj): action = obj.animation_data.action if obj and obj.animation_data else None if action is None: return {"name": None, "channels": []} 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(key.co.x), 6) for key in curve.keyframe_points], "values": [round(float(key.co.y), 6) for key in curve.keyframe_points]}) channels.sort(key=lambda value: (value["path"], value["index"])) return {"name": action.name, "channels": channels} def state_report(): objects = {name: bpy.data.objects.get(name) for name in OBJECTS} if any(obj is None for obj in objects.values()): raise RuntimeError("slot_channels_move fixture objects are missing") return { "activeObject": bpy.context.view_layer.objects.active.name if bpy.context.view_layer.objects.active else None, "objects": {name: action_report(obj) for name, obj in objects.items()}, "actions": {action.name: int(action.users) for action in bpy.data.actions}, } def is_moved(state): return state["objects"][OBJECTS[0]]["name"] != OLD_ACTION and state["objects"][OBJECTS[1]]["name"] == OLD_ACTION def run_operator(): window = bpy.context.window screen = window.screen area = next(candidate for candidate in screen.areas if candidate.type == "DOPESHEET_EDITOR" and candidate.height >= 200) area.spaces.active.ui_mode = "ACTION" region = next(candidate for candidate in area.regions if candidate.type == "WINDOW") with bpy.context.temp_override(window=window, screen=screen, area=area, region=region): poll = bool(bpy.ops.anim.slot_channels_move_to_new_action.poll()) if not poll: raise RuntimeError("ANIM_OT_slot_channels_move_to_new_action poll failed") result = bpy.ops.anim.slot_channels_move_to_new_action() if result != {"FINISHED"}: raise RuntimeError(f"ANIM_OT_slot_channels_move_to_new_action returned {result}") return poll, result def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --factory-startup --python check-action-slot-channels-move-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 = state_report() preserved = is_moved(before) if preserved: poll = True result = {"FINISHED"} else: poll, result = run_operator() after = state_report() if not is_moved(after): raise RuntimeError(f"slot_channels_move did not move the selected slot: {after}") descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-slot-channels-move-reopen-", suffix=".blend") os.close(descriptor) temporary_path = pathlib.Path(temporary) try: bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=True) reopened = state_report() if reopened != after: raise RuntimeError(f"anim.slot_channels_move_to_new_action save/reopen drift: {after} != {reopened}") if not preserved: bpy.ops.wm.save_as_mainfile(filepath=str(fixture), check_existing=False, compress=True) report = {"schemaVersion": 1, "task": "M16-GAP-00206", "operation": "ANIM_SLOT_CHANNELS_MOVE_TO_NEW_ACTION_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "before": before, "after": reopened, "poll": poll, "operatorStatus": "FINISHED", "mainMutation": "SLOT_MOVED_TO_NEW_ACTION" if not preserved else "NONE_ALREADY_MOVED", "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string} if preserved: report["evidenceStatus"] = "PRESERVED" if not preserved or not output.exists(): output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8") print("anim-slot-channels-move-desktop-ok poll=true status=FINISHED mainMutation=slot_moved saveReopen=exact") finally: temporary_path.unlink(missing_ok=True) if __name__ == "__main__": try: main() except Exception as error: print(f"anim-slot-channels-move-desktop-failed: {error}") raise SystemExit(1)