#!/usr/bin/env python3 import pathlib import sys import bpy ARMATURE_NAME = "WebGapArmatureCollectionRemoveArmature" OBJECT_NAME = "WebGapArmatureCollectionRemoveObject" FIRST_COLLECTION = "WebGapArmatureCollectionRemoveFirst" REMOVED_COLLECTION = "WebGapArmatureCollectionRemoveRemoved" LAST_COLLECTION = "WebGapArmatureCollectionRemoveLast" FIRST_BONE = "WebGapArmatureCollectionRemoveFirstBone" REMOVED_BONE = "WebGapArmatureCollectionRemoveRemovedBone" LAST_BONE = "WebGapArmatureCollectionRemoveLastBone" def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00226.py -- OUTPUT") bpy.ops.wm.read_factory_settings(use_empty=True) armature = bpy.data.armatures.new(ARMATURE_NAME) obj = bpy.data.objects.new(OBJECT_NAME, armature) bpy.context.scene.collection.objects.link(obj) first = armature.collections.new(FIRST_COLLECTION) removed = armature.collections.new(REMOVED_COLLECTION) last = armature.collections.new(LAST_COLLECTION) bpy.context.view_layer.objects.active = obj obj.select_set(True) bpy.ops.object.mode_set(mode="EDIT") for name, x in ((FIRST_BONE, 0.0), (REMOVED_BONE, 1.0), (LAST_BONE, 2.0)): bone = armature.edit_bones.new(name) bone.head = (x, 0.0, 0.0) bone.tail = (x, 1.0, 0.0) bpy.ops.object.mode_set(mode="OBJECT") first.assign(armature.bones[FIRST_BONE]) removed.assign(armature.bones[REMOVED_BONE]) last.assign(armature.bones[LAST_BONE]) armature.collections.active_index = 1 bpy.ops.wm.save_as_mainfile( filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True ) if __name__ == "__main__": main()