diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index 8e97bfabf3..3236395fa2 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -722,12 +722,12 @@ class IfcImporter: self.incrementally_merge_objects() shape = iterator.get() if shape: - product = self.file.by_id(shape.guid) + product = self.file.by_id(shape.id) if self.body_contexts: self.create_product(product, shape) results.add(product) else: - if shape.context not in ["Body", "Facetation"] and IfcStore.get_element(shape.guid): + if shape.context not in ["Body", "Facetation"] and IfcStore.get_element(shape.id): # We only load a single context, and we prioritise the Body context. See #1290. pass else: @@ -877,7 +877,7 @@ class IfcImporter: checkpoint = time.time() shape = iterator.get() if shape: - product = self.file.by_id(shape.guid) + product = self.file.by_id(shape.id) self.create_product(product, shape) results.add(product) if not iterator.next(): diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index bd18aa61ac..dbd8fc3145 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -382,7 +382,7 @@ class OverrideDeleteTrait: def delete_opening_element(self, element): obj = IfcStore.get_element(element.VoidsElements[0].RelatingBuildingElement.id()) - bpy.ops.bim.remove_opening(opening_id=element.id(), obj=obj.name) + bpy.ops.bim.remove_opening(opening_id=element.id()) def remove_filling(self, element): obj = IfcStore.get_element(element.id()) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index ee34dda5c9..531e34480b 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -17,6 +17,7 @@ # along with IfcOpenShell. If not, see . import ifcopenshell +import ifcopenshell.util.system import ifcopenshell.util.element @@ -69,6 +70,17 @@ class Usecase: continue elif inverse.is_a("IfcRelDefinesByType") and inverse.RelatingType == from_element: continue + elif inverse.is_a("IfcRelVoidsElement") and inverse.RelatingBuildingElement == from_element: + opening = inverse.RelatedOpeningElement + new_opening = ifcopenshell.api.run("root.copy_class", self.file, product=opening) + new_opening.VoidsElements[0].RelatingBuildingElement = to_element + if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"): + if to_element.ObjectPlacement: + new_opening.ObjectPlacement.PlacementRelTo = to_element.ObjectPlacement + # For now, we do copy opening representations + new_opening.Representation = ifcopenshell.util.element.copy_deep( + self.file, opening.Representation + ) elif inverse.is_a("IfcRelFillsElement"): continue elif inverse.is_a("IfcRelConnectsPathElements"): diff --git a/src/ifcopenshell-python/test/api/root/test_copy_class.py b/src/ifcopenshell-python/test/api/root/test_copy_class.py index 703419a44e..0be520f1e4 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -105,6 +105,16 @@ class TestCopyClass(test.bootstrap.IFC4): new = ifcopenshell.api.run("root.copy_class", self.file, product=element) assert new.RepresentationMaps is None + def test_copying_an_element_with_an_opening(self): + wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=wall) + new = ifcopenshell.api.run("root.copy_class", self.file, product=wall) + assert wall.HasOpenings[0] != new.HasOpenings[0] + assert wall.HasOpenings[0].RelatedOpeningElement == opening + assert new.HasOpenings[0].RelatedOpeningElement != opening + assert new.HasOpenings[0].RelatedOpeningElement.is_a("IfcOpeningElement") + def test_copying_an_opening_voiding_an_element(self): wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")