1919import ifcopenshell
2020import ifcopenshell .api .owner
2121import ifcopenshell .util .element
22- from typing import Union
2322
2423
2524def unassign_control (
2625 file : ifcopenshell .file ,
2726 relating_control : ifcopenshell .entity_instance ,
28- related_object : ifcopenshell .entity_instance ,
29- ) -> Union [ ifcopenshell . entity_instance , None ] :
27+ related_objects : list [ ifcopenshell .entity_instance ] ,
28+ ) -> None :
3029 """Unassigns a planning control or constraint to an object
3130
3231 :param relating_control: The IfcControl entity that is creating the
3332 control or constraint
34- :param related_object: The IfcObjectDefinition that is being controlled
35- :return: If the control still is related to other objects, the
36- IfcRelAssignsToControl is returned, otherwise None.
33+ :param related_objects: The list IfcObjectDefinitions that is being controlled
34+ :return: None
3735
3836 Example:
3937
@@ -49,19 +47,19 @@ def unassign_control(
4947
5048 # And now let's change our mind
5149 ifcopenshell.api.control.unassign_control(model,
52- relating_control=cost_item, related_object= wall)
50+ relating_control=cost_item, related_objects=[ wall] )
5351 """
54- for rel in related_object .HasAssignments or []:
55- if not rel .is_a ("IfcRelAssignsToControl" ) or rel .RelatingControl != relating_control :
56- continue
57- if len (rel .RelatedObjects ) == 1 :
52+ related_objects_set = set (related_objects )
53+ control_assignments = set (relating_control .Controls )
54+ rels = set (rel for obj in related_objects_set for rel in obj .HasAssignments if rel in control_assignments )
55+
56+ for rel in rels :
57+ related_objects_new = set (rel .RelatedObjects ) - related_objects_set
58+ if related_objects_new :
59+ rel .RelatedObjects = list (related_objects_new )
60+ ifcopenshell .api .owner .update_owner_history (file , element = rel )
61+ else :
5862 history = rel .OwnerHistory
5963 file .remove (rel )
6064 if history :
6165 ifcopenshell .util .element .remove_deep2 (file , history )
62- return
63- related_objects = list (rel .RelatedObjects )
64- related_objects .remove (related_object )
65- rel .RelatedObjects = related_objects
66- ifcopenshell .api .owner .update_owner_history (file , element = rel )
67- return rel
0 commit comments