#!/usr/bin/env python3 import pathlib import sys import bpy OLD_ACTION = "WebGapAnimSeparateSlotsAction" def make_object(name, action, slot, values): mesh = bpy.data.meshes.new(f"{name}Mesh") mesh.from_pydata( [(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)], [], [(0, 1, 2, 3)], ) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.collection.objects.link(obj) obj.animation_data_create() obj.animation_data.action = action obj.animation_data.action_slot = slot for frame, value in zip((1, 3, 5), values): obj["separate_target"] = value obj.keyframe_insert(data_path='["separate_target"]', frame=frame) return obj def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00205.py -- OUTPUT") bpy.ops.wm.read_factory_settings(use_empty=True) action = bpy.data.actions.new(OLD_ACTION) slot_a = action.slots.new("OBJECT", "WebGapSeparateSlotA") slot_b = action.slots.new("OBJECT", "WebGapSeparateSlotB") object_a = make_object("WebGapAnimSeparateSlotA", action, slot_a, (1.0, 3.0, 5.0)) object_b = make_object("WebGapAnimSeparateSlotB", action, slot_b, (2.0, 4.0, 6.0)) action.use_fake_user = True bpy.context.view_layer.objects.active = object_a object_a.select_set(True) object_b.select_set(False) bpy.context.scene.frame_start = 1 bpy.context.scene.frame_end = 5 bpy.context.scene.frame_set(3) bpy.ops.wm.save_as_mainfile( filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True ) if __name__ == "__main__": main()