diff --git a/src/blenderbim/blenderbim/bim/module/model/mep.py b/src/blenderbim/blenderbim/bim/module/model/mep.py index c3a19c5727..7531c79ae4 100644 --- a/src/blenderbim/blenderbim/bim/module/model/mep.py +++ b/src/blenderbim/blenderbim/bim/module/model/mep.py @@ -243,7 +243,6 @@ class MEPGenerator: def setup_ports(self, obj): self.file = tool.Ifc.get() - self.collection = bpy.context.view_layer.active_layer_collection.collection segment = tool.Ifc.get_entity(obj) representation = ifcopenshell.util.representation.get_representation(segment, "Model", "Body", "MODEL_VIEW") diff --git a/src/blenderbim/blenderbim/bim/module/model/product.py b/src/blenderbim/blenderbim/bim/module/model/product.py index 82b39fddbb..486d03f68f 100644 --- a/src/blenderbim/blenderbim/bim/module/model/product.py +++ b/src/blenderbim/blenderbim/bim/module/model/product.py @@ -192,9 +192,9 @@ class AddConstrTypeInstance(bpy.types.Operator): obj.location = context.scene.cursor.location - collection = context.view_layer.active_layer_collection.collection - collection.objects.link(obj) - collection_obj = collection.BIMCollectionProperties.obj + self.container_obj = None + if container := tool.Root.get_default_container(): + self.container_obj = tool.Ifc.get_object(container) bpy.ops.bim.assign_class(obj=obj.name, ifc_class=instance_class) tool.Blender.remove_data_block(mesh) # Remove "Instance" mesh @@ -248,11 +248,11 @@ class AddConstrTypeInstance(bpy.types.Operator): # TODO For now we are hardcoding windows and doors as a prototype bpy.ops.bim.add_filled_opening(voided_obj=building_obj.name, filling_obj=obj.name) else: - if collection_obj and tool.Ifc.get_entity(collection_obj): + if self.container_obj: if props.rl_mode == "BOTTOM": - obj.location.z = collection_obj.location.z - tool.Blender.get_object_bounding_box(obj)["min_z"] + obj.location.z = self.container_obj.location.z - tool.Blender.get_object_bounding_box(obj)["min_z"] elif props.rl_mode == "CONTAINER": - obj.location.z = collection_obj.location.z + obj.location.z = self.container_obj.location.z elif props.rl_mode == "CURSOR": pass @@ -274,11 +274,8 @@ class AddConstrTypeInstance(bpy.types.Operator): return {"FINISHED"} def set_flow_segment_rl(self, obj): - collection = bpy.context.view_layer.active_layer_collection.collection - collection_obj = collection.BIMCollectionProperties.obj - - if collection_obj and tool.Ifc.get_entity(collection_obj): - obj.location[2] = collection_obj.location[2] + bpy.context.scene.BIMModelProperties.rl2 + if self.container_obj: + obj.location[2] = self.container_obj.location[2] + bpy.context.scene.BIMModelProperties.rl2 @staticmethod def generate_layered_element(ifc_class: str, relating_type: ifcopenshell.entity_instance) -> bool: diff --git a/src/blenderbim/blenderbim/bim/module/model/slab.py b/src/blenderbim/blenderbim/bim/module/model/slab.py index cb0263e0f3..4e6da27e00 100644 --- a/src/blenderbim/blenderbim/bim/module/model/slab.py +++ b/src/blenderbim/blenderbim/bim/module/model/slab.py @@ -31,7 +31,6 @@ import blenderbim.core.type import blenderbim.core.geometry import blenderbim.core.root import blenderbim.tool as tool -from math import radians from mathutils import Vector, Matrix from blenderbim.bim.module.geometry.helper import Helper from blenderbim.bim.module.model.decorator import ProfileDecorator @@ -137,8 +136,10 @@ class DumbSlabGenerator: ) props = bpy.context.scene.BIMModelProperties - self.collection = bpy.context.view_layer.active_layer_collection.collection - self.collection_obj = self.collection.BIMCollectionProperties.obj + self.container = None + if container := tool.Root.get_default_container(): + self.container = container + self.container_obj = tool.Ifc.get_object(container) self.depth = sum(thicknesses) * unit_scale self.width = 3 self.length = 3 @@ -161,13 +162,12 @@ class DumbSlabGenerator: matrix_world = Matrix() matrix_world.translation = self.location - if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: - matrix_world.translation.z = self.collection_obj.location.z - self.depth + if self.container_obj: + matrix_world.translation.z = self.container_obj.location.z - self.depth else: matrix_world.translation.z -= self.depth obj.matrix_world = Matrix.Rotation(self.x_angle, 4, "X") @ matrix_world bpy.context.view_layer.update() - self.collection.objects.link(obj) element = blenderbim.core.root.assign_class( tool.Ifc, diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index d16b81fd1e..5dd6be2070 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -34,7 +34,7 @@ import blenderbim.core.root import blenderbim.core.geometry import blenderbim.tool as tool from blenderbim.bim.ifc import IfcStore -from math import pi, sin, cos, degrees, radians +from math import pi, sin, cos, degrees from mathutils import Vector, Matrix from blenderbim.bim.module.model.opening import FilledOpeningGenerator from typing import Optional @@ -449,8 +449,10 @@ class DumbWallGenerator: self.axis_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Plan", "Axis", "GRAPH_VIEW") props = bpy.context.scene.BIMModelProperties - self.collection = bpy.context.view_layer.active_layer_collection.collection - self.collection_obj = self.collection.BIMCollectionProperties.obj + self.container = None + if container := tool.Root.get_default_container(): + self.container = container + self.container_obj = tool.Ifc.get_object(container) self.width = self.layers["thickness"] self.height = props.extrusion_depth self.length = props.length @@ -540,11 +542,12 @@ class DumbWallGenerator: def derive_from_cursor(self): RAYCAST_PRECISION = 0.01 self.location = bpy.context.scene.cursor.location - if self.collection: - for sibling_obj in self.collection.objects: - if not isinstance(sibling_obj.data, bpy.types.Mesh): + if self.container: + for subelement in ifcopenshell.util.element.get_decomposition(self.container): + if not subelement.is_a("IfcWall"): continue - if "IfcWall" not in sibling_obj.name: + sibling_obj = tool.Ifc.get_object(subelement) + if not sibling_obj or not isinstance(sibling_obj.data, bpy.types.Mesh): continue inv_obj_matrix = sibling_obj.matrix_world.inverted() local_location = inv_obj_matrix @ self.location @@ -594,11 +597,10 @@ class DumbWallGenerator: matrix_world = Matrix.Rotation(self.rotation, 4, "Z") matrix_world.translation = self.location - if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: - matrix_world.translation.z = self.collection_obj.location.z + props.rl1 + if self.container_obj: + matrix_world.translation.z = self.container_obj.location.z + props.rl1 obj.matrix_world = matrix_world bpy.context.view_layer.update() - self.collection.objects.link(obj) element = blenderbim.core.root.assign_class( tool.Ifc,