Files
workinf_Blender_Wasm/tools/web/check-action-armature-collection-unsolo-all-desktop.py
mes123456 9f43244982
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Continue Blender Web parity task handoff
2026-08-23 05:47:21 -04:00

142 lines
5.7 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import shutil
import sys
import tempfile
import bpy
ARMATURE_NAME = "WebGapArmatureCollectionUnsoloAllArmature"
OBJECT_NAME = "WebGapArmatureCollectionUnsoloAllObject"
FIRST_COLLECTION = "WebGapArmatureCollectionUnsoloAllFirst"
SOLO_COLLECTION = "WebGapArmatureCollectionUnsoloAllSolo"
LAST_COLLECTION = "WebGapArmatureCollectionUnsoloAllLast"
FIRST_BONE = "WebGapArmatureCollectionUnsoloAllFirstBone"
SOLO_BONE = "WebGapArmatureCollectionUnsoloAllSoloBone"
LAST_BONE = "WebGapArmatureCollectionUnsoloAllLastBone"
def ensure_object():
obj = bpy.data.objects.get(OBJECT_NAME)
armature = bpy.data.armatures.get(ARMATURE_NAME)
if armature is None or obj is None or obj.type != "ARMATURE" or obj.data != armature:
raise RuntimeError("armature.collection_unsolo_all fixture is missing")
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
return armature
def state_report():
armature = ensure_object()
collections = []
for index, collection in enumerate(armature.collections):
collections.append(
{
"name": collection.name,
"index": index,
"visible": bool(collection.is_visible),
"solo": bool(collection.is_solo),
"bones": sorted(bone.name for bone in collection.bones),
}
)
return {
"object": OBJECT_NAME,
"armature": ARMATURE_NAME,
"activeIndex": armature.collections.active_index,
"isSoloActive": bool(armature.collections.is_solo_active),
"bones": sorted(bone.name for bone in armature.bones),
"collections": collections,
}
def run_operator(already_unsolo):
ensure_object()
poll = bool(bpy.ops.armature.collection_unsolo_all.poll())
if not already_unsolo:
if not poll:
raise RuntimeError("ARMATURE_OT_collection_unsolo_all poll failed")
result = bpy.ops.armature.collection_unsolo_all()
if result != {"FINISHED"}:
raise RuntimeError(f"ARMATURE_OT_collection_unsolo_all returned {result}")
return poll, not already_unsolo
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit(
"usage: blender -b --factory-startup --python check-action-armature-collection-unsolo-all-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 = state_report()
expected_collections = [FIRST_COLLECTION, SOLO_COLLECTION, LAST_COLLECTION]
if [collection["name"] for collection in before["collections"]] != expected_collections:
raise RuntimeError(f"unexpected collection_unsolo_all collections: {before}")
if before["activeIndex"] != 1:
raise RuntimeError(f"unexpected collection_unsolo_all active index: {before}")
solo_names = {collection["name"] for collection in before["collections"] if collection["solo"]}
if solo_names == set():
already_unsolo = True
elif solo_names == {SOLO_COLLECTION}:
already_unsolo = False
else:
raise RuntimeError(f"unexpected collection_unsolo_all solo input: {before}")
poll, changed = run_operator(already_unsolo)
after = state_report()
if after["isSoloActive"] or any(collection["solo"] for collection in after["collections"]):
raise RuntimeError(f"collection_unsolo_all did not clear every solo flag: {after}")
if after["activeIndex"] != 1:
raise RuntimeError(f"collection_unsolo_all changed active collection: {after}")
expected_members = {
FIRST_COLLECTION: [FIRST_BONE],
SOLO_COLLECTION: [SOLO_BONE],
LAST_COLLECTION: [LAST_BONE],
}
actual_members = {collection["name"]: collection["bones"] for collection in after["collections"]}
if actual_members != expected_members:
raise RuntimeError(f"collection_unsolo_all changed collection membership: {after}")
descriptor, temporary = tempfile.mkstemp(prefix="m16-armature-collection-unsolo-all-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=False)
reopened = state_report()
if reopened != after:
raise RuntimeError(f"armature.collection_unsolo_all save/reopen drift: {after} != {reopened}")
shutil.copyfile(temporary_path, fixture)
report = {
"schemaVersion": 1,
"task": "M16-GAP-00232",
"operation": "ARMATURE_COLLECTION_UNSOLO_ALL_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"before": before,
"after": reopened,
"soloCollection": SOLO_COLLECTION,
"poll": poll,
"operatorStatus": "FINISHED" if changed else "SKIPPED_ALREADY_APPLIED",
"mainMutation": "ALL_COLLECTIONS_UNSOLO" if changed else "ALL_COLLECTIONS_ALREADY_UNSOLO",
"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("armature-collection-unsolo-all-desktop-ok solo=none saveReopen=exact")
finally:
temporary_path.unlink(missing_ok=True)
if __name__ == "__main__":
try:
main()
except Exception as error:
print(f"armature-collection-unsolo-all-desktop-failed: {error}")
raise SystemExit(1)