101 lines
3.9 KiB
Python
101 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
def driver_report(obj):
|
|
if obj is None or obj.animation_data is None:
|
|
raise RuntimeError("driver-edit fixture animation data is missing")
|
|
drivers = []
|
|
for curve in obj.animation_data.drivers:
|
|
driver = curve.driver
|
|
drivers.append({
|
|
"path": curve.data_path,
|
|
"index": curve.array_index,
|
|
"expression": driver.expression if driver else "",
|
|
"type": driver.type if driver else "",
|
|
"variableCount": len(driver.variables) if driver else 0,
|
|
})
|
|
drivers.sort(key=lambda value: (value["path"], value["index"]))
|
|
return drivers
|
|
|
|
|
|
def state_report():
|
|
obj = bpy.data.objects.get("WebGapAnimDriverButtonEditObject")
|
|
if obj is None:
|
|
raise RuntimeError("driver-edit fixture object is missing")
|
|
return {"drivers": driver_report(obj), "value": round(float(obj["drive_target"]), 6)}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-action-driver-button-edit-desktop.py -- FIXTURE REPORT")
|
|
fixture, output = (pathlib.Path(value).resolve() for value in arguments)
|
|
output.unlink(missing_ok=True)
|
|
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False)
|
|
before = state_report()
|
|
expected = [{
|
|
"path": '["drive_target"]',
|
|
"index": 0,
|
|
"expression": "frame * 2.5 + 1.25",
|
|
"type": "SCRIPTED",
|
|
"variableCount": 0,
|
|
}]
|
|
if before["value"] != 3.75 or before["drivers"] != expected:
|
|
raise RuntimeError(f"unexpected driver_button_edit source state: {before}")
|
|
|
|
window = bpy.context.window
|
|
screen = window.screen
|
|
area = next(candidate for candidate in screen.areas if candidate.type == "PROPERTIES")
|
|
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.driver_button_edit.poll())
|
|
result = bpy.ops.anim.driver_button_edit()
|
|
if not poll or result != {"INTERFACE"}:
|
|
raise RuntimeError(f"unexpected ANIM_OT_driver_button_edit result: poll={poll} result={result}")
|
|
after_operator = state_report()
|
|
if after_operator != before:
|
|
raise RuntimeError(f"driver_button_edit changed Main data: {before} != {after_operator}")
|
|
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-driver-button-edit-reopen-", suffix=".blend")
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
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 = state_report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if after != before:
|
|
raise RuntimeError("anim.driver_button_edit save/reopen drift")
|
|
report = {
|
|
"schemaVersion": 1,
|
|
"task": "M16-GAP-00175",
|
|
"operation": "ANIM_DRIVER_BUTTON_EDIT_DESKTOP",
|
|
"fixture": str(fixture),
|
|
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
|
"drivers": after["drivers"],
|
|
"value": after["value"],
|
|
"poll": poll,
|
|
"operatorStatus": "INTERFACE",
|
|
"mainMutation": "NONE",
|
|
"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("anim-driver-button-edit-desktop-ok poll=true status=INTERFACE mainMutation=none saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except Exception as error:
|
|
print(f"anim-driver-button-edit-desktop-failed: {error}")
|
|
raise SystemExit(1)
|