#!/usr/bin/env python3 import pathlib import sys import bpy LIBRARY_NAME = "WebGapBundleInstall.blend" OBJECT_NAME = "WebGapBundleInstallObject" def reset(): bpy.ops.wm.read_factory_settings(use_empty=True) def create_source(path): reset() mesh = bpy.data.meshes.new("WebGapBundleInstallMesh") mesh.from_pydata([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)], [], [(0, 1, 2)]) obj = bpy.data.objects.new(OBJECT_NAME, mesh) bpy.context.scene.collection.objects.link(obj) bpy.ops.wm.save_as_mainfile(filepath=str(path), check_existing=False, compress=True) def create_fixture(output): source = output.with_name(LIBRARY_NAME) create_source(source) reset() with bpy.data.libraries.load(str(source), link=True) as (data_from, data_to): if OBJECT_NAME not in data_from.objects: raise RuntimeError("bundle-install source object is missing") data_to.objects = [OBJECT_NAME] linked = data_to.objects[0] if linked is None: raise RuntimeError("bundle-install linked object is missing") bpy.context.scene.collection.objects.link(linked) bpy.ops.wm.save_as_mainfile(filepath=str(output), check_existing=False, compress=True) def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00268.py -- OUTPUT") output = pathlib.Path(arguments[0]).resolve() output.parent.mkdir(parents=True, exist_ok=True) create_fixture(output) if __name__ == "__main__": main()