diff --git a/src/bonsai/bonsai/core/structural.py b/src/bonsai/bonsai/core/structural.py index af092e1034..bae45ada33 100644 --- a/src/bonsai/bonsai/core/structural.py +++ b/src/bonsai/bonsai/core/structural.py @@ -43,7 +43,7 @@ def assign_structural_analysis_model( ifc.run( "structural.assign_structural_analysis_model", **{ - "product": ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id), + "products": [ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id)], "structural_analysis_model": ifc.get().by_id(structural_analysis_model), }, ) @@ -110,7 +110,7 @@ def unassign_structural_analysis_model( ifc.run( "structural.unassign_structural_analysis_model", **{ - "product": ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id), + "products": [ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id)], "structural_analysis_model": ifc.get().by_id(structural_analysis_model), }, ) diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/assign_structural_analysis_model.py b/src/ifcopenshell-python/ifcopenshell/api/structural/assign_structural_analysis_model.py index dd96f543b2..dfae40d862 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/assign_structural_analysis_model.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/assign_structural_analysis_model.py @@ -17,43 +17,22 @@ # along with IfcOpenShell. If not, see . import ifcopenshell +import ifcopenshell.api.group import ifcopenshell.api.owner import ifcopenshell.guid +from typing import Union def assign_structural_analysis_model( file: ifcopenshell.file, - product: ifcopenshell.entity_instance, + products: list[ifcopenshell.entity_instance], structural_analysis_model: ifcopenshell.entity_instance, -) -> ifcopenshell.entity_instance: +) -> Union[ifcopenshell.entity_instance, None]: """Assigns a load or structural member to an analysis model - :param product: The structural element that is part of the analysis. - :type product: ifcopenshell.entity_instance + :param products: The structural elements that is part of the analysis. :param structural_analysis_model: The IfcStructuralAnalysisModel that the structural element is related to. - :type structural_analysis_model: ifcopenshell.entity_instance :return: The IfcRelAssignsToGroup relationship - :rtype: ifcopenshell.entity_instance """ - settings = { - "product": product, - "structural_analysis_model": structural_analysis_model, - } - - if not settings["structural_analysis_model"].IsGroupedBy: - return file.create_entity( - "IfcRelAssignsToGroup", - **{ - "GlobalId": ifcopenshell.guid.new(), - "OwnerHistory": ifcopenshell.api.owner.create_owner_history(file), - "RelatedObjects": [settings["product"]], - "RelatingGroup": settings["structural_analysis_model"], - } - ) - rel = settings["structural_analysis_model"].IsGroupedBy[0] - related_objects = set(rel.RelatedObjects) or set() - related_objects.add(settings["product"]) - rel.RelatedObjects = list(related_objects) - ifcopenshell.api.owner.update_owner_history(file, **{"element": rel}) - return rel + return ifcopenshell.api.group.assign_group(file, products, structural_analysis_model) diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/unassign_structural_analysis_model.py b/src/ifcopenshell-python/ifcopenshell/api/structural/unassign_structural_analysis_model.py index 6fd53aa80d..2053e7d075 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/unassign_structural_analysis_model.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/unassign_structural_analysis_model.py @@ -17,40 +17,21 @@ # along with IfcOpenShell. If not, see . import ifcopenshell +import ifcopenshell.api.group import ifcopenshell.api.owner import ifcopenshell.util.element def unassign_structural_analysis_model( file: ifcopenshell.file, - product: ifcopenshell.entity_instance, + products: list[ifcopenshell.entity_instance], structural_analysis_model: ifcopenshell.entity_instance, ) -> None: """Removes a relationship between a structural element and the analysis model - :param product: The structural element that is part of the analysis. - :type product: ifcopenshell.entity_instance + :param products: The structural elements that is part of the analysis. :param structural_analysis_model: The IfcStructuralAnalysisModel that the structural element is related to. - :type structural_analysis_model: ifcopenshell.entity_instance :return: None - :rtype: None """ - settings = { - "product": product, - "structural_analysis_model": structural_analysis_model, - } - - if not settings["structural_analysis_model"].IsGroupedBy: - return - rel = settings["structural_analysis_model"].IsGroupedBy[0] - related_objects = set(rel.RelatedObjects) or set() - related_objects.remove(settings["product"]) - if len(related_objects): - rel.RelatedObjects = list(related_objects) - ifcopenshell.api.owner.update_owner_history(file, **{"element": rel}) - else: - history = rel.OwnerHistory - file.remove(rel) - if history: - ifcopenshell.util.element.remove_deep2(file, history) + ifcopenshell.api.group.unassign_group(file, products, structural_analysis_model) diff --git a/src/ifcopenshell-python/test/api/structural/test_assign_structural_analysis_model.py b/src/ifcopenshell-python/test/api/structural/test_assign_structural_analysis_model.py index 4e8cbb0f00..da09c38674 100644 --- a/src/ifcopenshell-python/test/api/structural/test_assign_structural_analysis_model.py +++ b/src/ifcopenshell-python/test/api/structural/test_assign_structural_analysis_model.py @@ -29,12 +29,13 @@ class TestAssignStructuralAnalysisModel(test.bootstrap.IFC4): ) rel = ifcopenshell.api.structural.assign_structural_analysis_model( self.file, - product=product, + products=[product], structural_analysis_model=subject, ) + assert rel assert rel.is_a("IfcRelAssignsToGroup") assert rel.RelatingGroup == subject - assert product in rel.RelatedObjects + assert rel.RelatedObjects == (product,) class TestAssignStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestAssignStructuralAnalysisModel): diff --git a/src/ifcopenshell-python/test/api/structural/test_unassign_structural_analysis_model.py b/src/ifcopenshell-python/test/api/structural/test_unassign_structural_analysis_model.py index e43fe1eaa0..c80842b7ad 100644 --- a/src/ifcopenshell-python/test/api/structural/test_unassign_structural_analysis_model.py +++ b/src/ifcopenshell-python/test/api/structural/test_unassign_structural_analysis_model.py @@ -29,12 +29,12 @@ class TestUnassignStructuralAnalysisModel(test.bootstrap.IFC4): ) ifcopenshell.api.structural.assign_structural_analysis_model( self.file, - product=product, + products=[product], structural_analysis_model=subject, ) ifcopenshell.api.structural.unassign_structural_analysis_model( self.file, - product=product, + products=[product], structural_analysis_model=subject, ) models = self.file.by_type("IfcStructuralAnalysisModel")