diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_role.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_role.py index 10c648cca5..f3869e7579 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_role.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_role.py @@ -42,7 +42,8 @@ def remove_role(file: ifcopenshell.file, role: ifcopenshell.entity_instance) -> if inverse.is_a() in ("IfcOrganization", "IfcPerson", "IfcPersonAndOrganization"): if inverse.Roles == (role,): inverse.Roles = None - elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"): - if inverse.RelatedResourceObjects == (organisation,): + elif inverse.is_a("IfcResourceLevelRelationship"): + # IfcResourceConstraintRelationship or other rels with IfcResourceObjectSelect. + if inverse.RelatedResourceObjects == (role,): file.remove(inverse) file.remove(role) diff --git a/src/ifcopenshell-python/test/api/owner/test_remove_role.py b/src/ifcopenshell-python/test/api/owner/test_remove_role.py index 5aa45e6645..0c2afcdd99 100644 --- a/src/ifcopenshell-python/test/api/owner/test_remove_role.py +++ b/src/ifcopenshell-python/test/api/owner/test_remove_role.py @@ -49,20 +49,21 @@ class TestRemoveRoleIFC2X3(test.bootstrap.IFC2X3): class TestRemoveRoleIFC4(test.bootstrap.IFC4, TestRemoveRoleIFC2X3): + # IfcResourceLevelRelationships were added in IFC4. def test_deleting_resource_approval_relationships(self): - organisation = self.file.create_entity("IfcOrganization") - self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[organisation]) - ifcopenshell.api.owner.remove_organisation(self.file, organisation=organisation) + role = self.file.create_entity("IfcActorRole") + self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[role]) + ifcopenshell.api.owner.remove_role(self.file, role=role) assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0 def test_deleting_resource_constraint_relationships(self): - organisation = self.file.create_entity("IfcOrganization") - self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[organisation]) - ifcopenshell.api.owner.remove_organisation(self.file, organisation=organisation) + role = self.file.create_entity("IfcActorRole") + self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[role]) + ifcopenshell.api.owner.remove_role(self.file, role=role) assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0 def test_deleting_external_reference_relationships(self): - organisation = self.file.create_entity("IfcOrganization") - self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[organisation]) - ifcopenshell.api.owner.remove_organisation(self.file, organisation=organisation) + role = self.file.create_entity("IfcActorRole") + self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[role]) + ifcopenshell.api.owner.remove_role(self.file, role=role) assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0