ifcopenshell.util - make ifc_file argument optional if it can be deduced from ifc element

This commit is contained in:
Andrej730
2025-03-07 12:07:14 +05:00
parent 590288496e
commit eb0d3c38b2
4 changed files with 43 additions and 13 deletions
@@ -140,7 +140,7 @@ def get_subtypes(
def reassign_class(
ifc_file: ifcopenshell.file, element: ifcopenshell.entity_instance, new_class: str
ifc_file: Union[ifcopenshell.file, None], element: ifcopenshell.entity_instance, new_class: str
) -> ifcopenshell.entity_instance:
"""
Attempts to change the class (entity name) of `element` to `new_class` by
@@ -156,6 +156,9 @@ def reassign_class(
It's unlikely that this affects real-world usage of this function.
"""
if not ifc_file:
ifc_file = element.file
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(ifc_file.schema)
try:
declaration = schema.declaration_by_name(new_class)