#!/usr/bin/env python3 import pathlib import sys import bpy ARMATURE_NAME = "WebGapVersionBoneHideArmature" OBJECT_NAME = "WebGapVersionBoneHideObject" BONE_NAME = "WebGapVersionBoneHideBone" ARMATURE_ACTION_NAME = "WebGapVersionBoneHideArmatureAction" OBJECT_ACTION_NAME = "WebGapVersionBoneHideObjectAction" def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00213.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) bpy.context.view_layer.objects.active = obj obj.select_set(True) bpy.ops.object.mode_set(mode="EDIT") bone = armature.edit_bones.new(BONE_NAME) bone.head = (0.0, 0.0, 0.0) bone.tail = (0.0, 1.0, 0.0) bpy.ops.object.mode_set(mode="OBJECT") armature.animation_data_create() armature_action = bpy.data.actions.new(ARMATURE_ACTION_NAME) armature_slot = armature_action.slots.new("ARMATURE", ARMATURE_NAME) armature.animation_data.action = armature_action armature.animation_data.action_slot = armature_slot armature.bones[BONE_NAME].hide = False armature.bones[BONE_NAME].keyframe_insert(data_path="hide", frame=1) armature.bones[BONE_NAME].hide = True armature.bones[BONE_NAME].keyframe_insert(data_path="hide", frame=10) armature_action.use_fake_user = True obj.animation_data_create() object_action = bpy.data.actions.new(OBJECT_ACTION_NAME) object_slot = object_action.slots.new("OBJECT", OBJECT_NAME) obj.animation_data.action = object_action obj.animation_data.action_slot = object_slot obj["version_anchor"] = 0.0 obj.keyframe_insert(data_path='["version_anchor"]', frame=1) obj["version_anchor"] = 1.0 obj.keyframe_insert(data_path='["version_anchor"]', frame=10) object_action.use_fake_user = True scene = bpy.context.scene scene.frame_start = 1 scene.frame_end = 10 scene.frame_set(5) bpy.ops.wm.save_as_mainfile( filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True ) if __name__ == "__main__": main()