ifcopenshell.api.run to use explicit kwargs instead of unpacking

This commit is contained in:
Andrej
2025-06-10 11:02:54 +05:00
parent a37d46ca3d
commit 1608677d40
52 changed files with 118 additions and 147 deletions
@@ -123,7 +123,7 @@ def assign_object(
related_objects = set(decomposes.RelatedObjects) - products_set
if related_objects:
decomposes.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": decomposes})
ifcopenshell.api.owner.update_owner_history(file, element=decomposes)
else:
history = decomposes.OwnerHistory
file.remove(decomposes)
@@ -133,7 +133,7 @@ def assign_object(
# assign elements to a new aggregate
if is_decomposed_by:
is_decomposed_by.RelatedObjects = list(set(is_decomposed_by.RelatedObjects) | products_set)
ifcopenshell.api.owner.update_owner_history(file, **{"element": is_decomposed_by})
ifcopenshell.api.owner.update_owner_history(file, element=is_decomposed_by)
else:
is_decomposed_by = file.create_entity(
"IfcRelAggregates",
@@ -69,7 +69,7 @@ def unassign_object(file: ifcopenshell.file, products: list[ifcopenshell.entity_
related_objects = set(rel.RelatedObjects) - products
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -86,4 +86,4 @@ def edit_attributes(file: ifcopenshell.file, product: ifcopenshell.entity_instan
product.PredefinedType = "USERDEFINED"
if hasattr(product, "OwnerHistory"):
ifcopenshell.api.owner.update_owner_history(file, **{"element": product})
ifcopenshell.api.owner.update_owner_history(file, element=product)
@@ -231,7 +231,7 @@ class Usecase:
if root_rel:
related_objects = set(root_rel.RelatedObjects) | self.rooted_products
root_rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": root_rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=root_rel)
else:
self.file.create_entity(
"IfcRelAssociatesClassification",
@@ -88,7 +88,7 @@ def remove_reference(
related_objects = set(rel.RelatedObjects) - rooted_products
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -70,7 +70,7 @@ class Usecase:
if rel:
related_objects = set(rel.RelatedObjects) | products_to_assign
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
return rel
return self.file.create_entity(
@@ -63,7 +63,7 @@ class Usecase:
related_objects -= products_set
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
continue
history = rel.OwnerHistory
@@ -84,7 +84,7 @@ def assign_control(
related_objects = set(controls.RelatedObjects)
related_objects.add(related_object)
controls.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": controls})
ifcopenshell.api.owner.update_owner_history(file, element=controls)
else:
controls = file.create_entity(
"IfcRelAssignsToControl",
@@ -63,5 +63,5 @@ def unassign_control(
related_objects = list(rel.RelatedObjects)
related_objects.remove(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
return rel
@@ -68,7 +68,7 @@ def unassign_document(
related_objects = set(rel.RelatedObjects) - products_set
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -75,7 +75,7 @@ class Usecase:
self.file, representation=self.settings["representation"]
)
self.assign_product_representation(element, mapped_representation)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": self.settings["product"]})
ifcopenshell.api.owner.update_owner_history(self.file, element=self.settings["product"])
def assign_product_representation(
self, product: ifcopenshell.entity_instance, representation: ifcopenshell.entity_instance
@@ -101,7 +101,7 @@ class Usecase:
new_placement.PlacementRelTo = placement_rel_to
self.settings["product"].ObjectPlacement = new_placement
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": self.settings["product"]})
ifcopenshell.api.owner.update_owner_history(self.file, element=self.settings["product"])
for settings in children_settings:
self.settings = settings
@@ -63,5 +63,5 @@ def assign_group(
if products_set.issubset(related_objects):
return rel
rel.RelatedObjects = list(related_objects | products_set)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
return rel
@@ -54,7 +54,7 @@ def unassign_group(
related_objects -= products_set
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -70,7 +70,7 @@ def unassign_reference(
related_objects = set(rel.RelatedObjects) - products_set
if related_objects:
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -328,7 +328,7 @@ class Usecase:
return self.create_material_association(material)
previous_related_objects = set(rel.RelatedObjects)
rel.RelatedObjects = list(previous_related_objects | self.products)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
return rel
def create_material_association(
@@ -132,4 +132,4 @@ class Usecase:
ifcopenshell.util.element.remove_deep2(self.file, history)
continue
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
@@ -146,7 +146,7 @@ def assign_object(
cur_related_objects = [o for o in nests.RelatedObjects if o not in related_objects_set]
if cur_related_objects:
nests.RelatedObjects = list(cur_related_objects)
ifcopenshell.api.owner.update_owner_history(file, **{"element": nests})
ifcopenshell.api.owner.update_owner_history(file, element=nests)
else:
history = nests.OwnerHistory
file.remove(nests)
@@ -160,7 +160,7 @@ def assign_object(
is_nested_by.RelatedObjects = cur_related_objects + [
o for o in related_objects if o not in cur_related_objects_set
]
ifcopenshell.api.owner.update_owner_history(file, **{"element": is_nested_by})
ifcopenshell.api.owner.update_owner_history(file, element=is_nested_by)
else:
is_nested_by = file.create_entity(
"IfcRelNests",
@@ -33,7 +33,7 @@ def change_nest(
related_objects.remove(item)
if related_objects:
nests.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": nests})
ifcopenshell.api.owner.update_owner_history(file, element=nests)
else:
history = nests.OwnerHistory
file.remove(nests)
@@ -66,7 +66,7 @@ def unassign_object(file: ifcopenshell.file, related_objects: list[ifcopenshell.
cur_related_objects = [o for o in rel.RelatedObjects if o not in related_objects_set]
if cur_related_objects:
rel.RelatedObjects = cur_related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -85,7 +85,7 @@ def assign_actor(
related_objects = list(rel.RelatedObjects)
related_objects.append(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
rel = file.create_entity(
"IfcRelAssignsToActor",
@@ -64,4 +64,4 @@ def unassign_actor(
related_objects = list(rel.RelatedObjects)
related_objects.remove(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
@@ -123,7 +123,7 @@ def assign_declaration(
related_definitions = set(has_context.RelatedDefinitions) - set(objects_with_contexts)
if related_definitions:
has_context.RelatedDefinitions = list(related_definitions)
ifcopenshell.api.owner.update_owner_history(file, **{"element": has_context})
ifcopenshell.api.owner.update_owner_history(file, element=has_context)
else:
history = has_context.OwnerHistory
file.remove(has_context)
@@ -133,7 +133,7 @@ def assign_declaration(
declares = next(iter(all_declares), None)
if declares:
declares.RelatedDefinitions = list(set(declares.RelatedDefinitions) | set(objects_to_change))
ifcopenshell.api.owner.update_owner_history(file, **{"element": declares})
ifcopenshell.api.owner.update_owner_history(file, element=declares)
else:
declares = file.create_entity(
"IfcRelDeclares",
@@ -67,7 +67,7 @@ def unassign_declaration(
related_definitions = set(rel.RelatedDefinitions) - definitions
if related_definitions:
rel.RelatedDefinitions = list(related_definitions)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -92,7 +92,7 @@ def assign_resource(
related_objects = list(resource_of.RelatedObjects)
related_objects.append(related_object)
resource_of.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": resource_of})
ifcopenshell.api.owner.update_owner_history(file, element=resource_of)
else:
resource_of = file.create_entity(
"IfcRelAssignsToResource",
@@ -69,4 +69,4 @@ def unassign_resource(
related_objects = list(rel.RelatedObjects)
related_objects.remove(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
@@ -100,10 +100,8 @@ def add_work_schedule(
if work_plan:
ifcopenshell.api.aggregate.assign_object(
file,
**{
"products": [work_schedule],
"relating_object": work_plan,
}
products=[work_schedule],
relating_object=work_plan,
)
elif file.schema != "IFC2X3":
# TODO: this is an ambiguity by buildingSMART
@@ -101,7 +101,7 @@ def assign_process(
related_objects = list(operates_on.RelatedObjects)
related_objects.append(related_object)
operates_on.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": operates_on})
ifcopenshell.api.owner.update_owner_history(file, element=operates_on)
else:
operates_on = file.create_entity(
"IfcRelAssignsToProcess",
@@ -77,7 +77,7 @@ def assign_product(
related_objects = list(referenced_by.RelatedObjects)
related_objects.append(related_object)
referenced_by.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": referenced_by})
ifcopenshell.api.owner.update_owner_history(file, element=referenced_by)
else:
referenced_by = file.create_entity(
"IfcRelAssignsToProduct",
@@ -94,7 +94,7 @@ class Usecase:
related_objects = list(referenced_by.RelatedObjects)
related_objects.append(related_object)
referenced_by.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": referenced_by})
ifcopenshell.api.owner.update_owner_history(self.file, element=referenced_by)
else:
referenced_by = self.file.create_entity(
"IfcRelDefinesByObject",
@@ -166,7 +166,7 @@ class Usecase:
related_objects = list(referenced_by.RelatedObjects)
related_objects.append(related_object)
referenced_by.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": referenced_by})
ifcopenshell.api.owner.update_owner_history(self.file, element=referenced_by)
else:
referenced_by = self.file.create_entity(
"IfcRelDefinesByObject",
@@ -139,7 +139,7 @@ def assign_container(
related_elements = set(rel.RelatedElements) - products_set
if related_elements:
rel.RelatedElements = list(related_elements)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -149,7 +149,7 @@ def assign_container(
# assign elements to a new container
if structure_rel:
structure_rel.RelatedElements = list(set(structure_rel.RelatedElements) | products_set)
ifcopenshell.api.owner.update_owner_history(file, **{"element": structure_rel})
ifcopenshell.api.owner.update_owner_history(file, element=structure_rel)
else:
structure_rel = file.create_entity(
"IfcRelContainedInSpatialStructure",
@@ -74,7 +74,7 @@ def dereference_structure(
related_elements = related_elements - products_set
if related_elements:
rel.RelatedElements = list(related_elements)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)
@@ -64,7 +64,7 @@ def assign_flow_control(
related_flow_controls = set(assignment.RelatedControlElements)
related_flow_controls.add(related_flow_control)
assignment.RelatedControlElements = list(related_flow_controls)
ifcopenshell.api.owner.update_owner_history(file, **{"element": assignment})
ifcopenshell.api.owner.update_owner_history(file, element=assignment)
return assignment
assignment = file.create_entity(
@@ -83,7 +83,7 @@ class Usecase:
related_objects = set(rel.RelatedObjects) or set()
related_objects.add(self.port)
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
else:
rel = self.file.create_entity(
"IfcRelNests",
@@ -64,4 +64,4 @@ def unassign_flow_control(
related_flow_controls = list(assignment.RelatedControlElements)
related_flow_controls.remove(related_flow_control)
assignment.RelatedControlElements = related_flow_controls
ifcopenshell.api.owner.update_owner_history(file, **{"element": assignment})
ifcopenshell.api.owner.update_owner_history(file, element=assignment)
@@ -74,7 +74,7 @@ class Usecase:
related_objects = set(rel.RelatedObjects) or set()
related_objects.remove(port)
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, element=rel)
def execute_ifc2x3(self) -> None:
for rel in self.element.HasPorts or []:
@@ -228,7 +228,7 @@ class Usecase:
cur_related_objects = set(is_typed_by.RelatedObjects) - related_objects_set
if cur_related_objects:
is_typed_by.RelatedObjects = list(cur_related_objects)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": is_typed_by})
ifcopenshell.api.owner.update_owner_history(self.file, element=is_typed_by)
else:
history = is_typed_by.OwnerHistory
self.file.remove(is_typed_by)
@@ -238,7 +238,7 @@ class Usecase:
# assign objects to a new type
if types:
types.RelatedObjects = list(set(types.RelatedObjects) | related_objects_set)
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": types})
ifcopenshell.api.owner.update_owner_history(self.file, element=types)
else:
types = self.file.create_entity(
"IfcRelDefinesByType",
@@ -63,7 +63,7 @@ def unassign_type(file: ifcopenshell.file, related_objects: list[ifcopenshell.en
related_objects_set = set(rel.RelatedObjects) - related_objects_set
if related_objects_set:
rel.RelatedObjects = list(related_objects_set)
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, element=rel)
else:
history = rel.OwnerHistory
file.remove(rel)