"""Writes build/kazah_objects.json: the visible mesh objects of the Tender file, so the interior build can link exactly those for the picture. blender -b --factory-startup models/Kazah-stern-cavity-fixedv4.blend --python build/list_kazah.py""" import json import os import bpy from mathutils import Vector names = [o.name for o in bpy.context.scene.objects if o.type == "MESH" and o.visible_get()] lo = Vector((1e9, 1e9, 1e9)) hi = Vector((-1e9, -1e9, -1e9)) for n in names: o = bpy.data.objects[n] for c in o.bound_box: p = o.matrix_world @ Vector(c) lo = Vector((min(lo.x, p.x), min(lo.y, p.y), min(lo.z, p.z))) hi = Vector((max(hi.x, p.x), max(hi.y, p.y), max(hi.z, p.z))) with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "kazah_objects.json"), "w", encoding="utf-8") as f: json.dump(names, f, indent=0) print("KAZAH %d visible meshes, bounds %s .. %s" % (len(names), [round(v, 2) for v in lo], [round(v, 2) for v in hi]))