From a1fb2771889d0f9322dd528290a3451bf5b52461 Mon Sep 17 00:00:00 2001 From: Gorgious Date: Thu, 27 Jan 2022 14:46:13 +0100 Subject: [PATCH] Tool to add storey to specific building --- src/blenderbim/blenderbim/core/spatial.py | 3 +++ src/blenderbim/blenderbim/tool/spatial.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/blenderbim/blenderbim/core/spatial.py b/src/blenderbim/blenderbim/core/spatial.py index e256eb894f..820b327916 100644 --- a/src/blenderbim/blenderbim/core/spatial.py +++ b/src/blenderbim/blenderbim/core/spatial.py @@ -83,3 +83,6 @@ def select_similar_container(ifc, spatial, obj=None): obj = ifc.get_object(subelement) if obj: spatial.select_object(obj) + +def add_storey_to_building(spatial, obj): + spatial.add_building_storey(building=obj) diff --git a/src/blenderbim/blenderbim/tool/spatial.py b/src/blenderbim/blenderbim/tool/spatial.py index f521463861..c70e23fd2a 100644 --- a/src/blenderbim/blenderbim/tool/spatial.py +++ b/src/blenderbim/blenderbim/tool/spatial.py @@ -117,3 +117,21 @@ class Spatial(blenderbim.core.tool.Spatial): @classmethod def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): target_obj.matrix_world = relative_to_obj.matrix_world @ matrix + + @classmethod + def get_name(cls, ifc_class, name): + if not bpy.data.objects.get(f"{ifc_class}/{name}"): + return name + i = 2 + while bpy.data.objects.get(f"{ifc_class}/{name} {i}"): + i += 1 + return f"{name} {i}" + + @classmethod + def add_building_storey(cls, building): + building_storey = bpy.data.objects.new(cls.get_name("IfcBuildingStorey", "My Storey"), None) + bpy.ops.bim.assign_class(obj=building_storey.name, ifc_class="IfcBuildingStorey") + blenderbim.core.aggregate.assign_object( + tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=building, related_obj=building_storey + ) + cls.set_active_object(building)