import bpy import json import pathlib import sys request = json.loads(pathlib.Path(sys.argv[sys.argv.index("--") + 1]).read_text()) def vector(values): return [round(float(value), 6) for value in values] states = {} for label, file in request["files"].items(): bpy.ops.wm.open_mainfile(filepath=str(pathlib.Path(file).resolve())) obj = bpy.data.objects["PoseConstraintArmatureObject"] states[label] = { "mirrorX": obj.data.use_mirror_x, "bones": [{ "name": bone.name, "parent": bone.parent.name if bone.parent else None, "connected": bone.use_connect, "head": vector(bone.head_local), "tail": vector(bone.tail_local), "matrix": [vector(row) for row in bone.matrix_local], } for bone in sorted(obj.data.bones, key=lambda bone: bone.name)], "constraints": [{ "bone": bone.name, "items": [{"name": constraint.name, "type": constraint.type, "target": constraint.target.name if getattr(constraint, "target", None) else None, "subtarget": getattr(constraint, "subtarget", ""), "influence": round(float(constraint.influence), 6), "enabled": not constraint.mute} for constraint in bone.constraints], } for bone in sorted(obj.pose.bones, key=lambda bone: bone.name)], } pathlib.Path(request["output"]).write_text(json.dumps(states, indent=2) + "\n")