From c0306fc7295e22e061399a84ea27ff9e15d759f8 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 28 Jan 2025 14:59:01 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/module/project/operator.py | 1 + .../ifcopenshell/api/geometry/edit_object_placement.py | 5 ++++- src/ifcopenshell-python/ifcopenshell/file.py | 3 +++ src/ifcopenshell-python/ifcopenshell/util/element.py | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 54fe5b1a2c..1ef8fd022d 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1948,6 +1948,7 @@ class AppendInspectedLinkedElement(AppendLibraryElement): queried_obj = context.scene.BIMProjectProperties.queried_obj ifc_file = tool.Ifc.get() + linked_ifc_file: ifcopenshell.file linked_ifc_file = ifcopenshell.open(queried_obj["ifc_filepath"]) if ifc_file.schema_identifier != linked_ifc_file.schema_identifier: self.report( diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py index 3351ed3da4..f5a52f13a4 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py @@ -22,7 +22,7 @@ import ifcopenshell.api.owner import ifcopenshell.util.unit import ifcopenshell.util.element import ifcopenshell.util.placement -from typing import Optional, Union +from typing import Optional, Union, Any NPArrayOfFloats = npt.NDArray[np.float64] @@ -46,6 +46,9 @@ def edit_object_placement( class Usecase: + file: ifcopenshell.file + settings: dict[str, Any] + def execute(self): if not hasattr(self.settings["product"], "ObjectPlacement"): return diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index e051ebf07c..59ac353107 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -226,6 +226,9 @@ class file: units: dict[str, entity_instance] = {} history_size: int = 64 + to_delete: Union[set[ifcopenshell.entity_instance], None] = None + """Entities for batch removal.""" + def __init__( self, f: Optional[ifcopenshell_wrapper.file] = None, diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index b4d90ce464..4355505f21 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1416,6 +1416,7 @@ def unbatch_remove_deep2(ifc_file: ifcopenshell.file) -> ifcopenshell.file: :param ifc_file: The IFC file object :return: A newly loaded file with the elements removed. """ + assert ifc_file.to_delete is not None ifc_string = ifc_file.to_string() lines = iter(ifc_string.split("\n")) ids_to_delete = iter(sorted([e.id() for e in ifc_file.to_delete])) @@ -1517,7 +1518,7 @@ def remove_deep2( if isinstance(attribute, tuple) and len(attribute) > 10: subelement[i] = [] - if getattr(ifc_file, "to_delete", None) is not None: + if ifc_file.to_delete is not None: ifc_file.to_delete.update(to_delete) return