92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
def action_view_report():
|
|
screen = None
|
|
area = None
|
|
for candidate_screen in bpy.data.screens:
|
|
candidate_area = next(
|
|
(candidate for candidate in candidate_screen.areas
|
|
if candidate.type == "DOPESHEET_EDITOR" and candidate.spaces.active.ui_mode == "ACTION"),
|
|
None,
|
|
)
|
|
if candidate_area is not None:
|
|
screen, area = candidate_screen, candidate_area
|
|
break
|
|
if area is None:
|
|
raise RuntimeError("Action Editor area is missing")
|
|
region = next((candidate for candidate in area.regions if candidate.type == "WINDOW"), None)
|
|
if region is None:
|
|
raise RuntimeError("Action Editor window region is missing")
|
|
view = region.view2d
|
|
xmin, ymin = view.region_to_view(0, 0)
|
|
xmax, ymax = view.region_to_view(region.width - 1, region.height - 1)
|
|
return {
|
|
"areaType": area.type,
|
|
"uiMode": area.spaces.active.ui_mode,
|
|
"currentFrame": int(bpy.context.scene.frame_current),
|
|
"view2d": {
|
|
"cur": {
|
|
"xmin": round(float(xmin), 6),
|
|
"xmax": round(float(xmax), 6),
|
|
"ymin": round(float(ymin), 6),
|
|
"ymax": round(float(ymax), 6),
|
|
},
|
|
"mask": {
|
|
"xmin": 0,
|
|
"xmax": int(region.width - 1),
|
|
"ymin": 0,
|
|
"ymax": int(region.height - 1),
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-action-view-frame-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 = action_view_report()
|
|
if before["currentFrame"] != 3:
|
|
raise RuntimeError(f"unexpected current frame: {before}")
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-action-view-frame-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=True)
|
|
after = action_view_report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"action.view_frame save/reopen drift: {before} != {after}")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00148",
|
|
"operation": "ACTION_VIEW_FRAME_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-view-frame-desktop-ok area=DOPESHEET_EDITOR mode=ACTION currentFrame=3 "
|
|
"saveReopen=exact"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|