From fc37cca1d0219ae284e682ab21c84625a4309a69 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 11 Apr 2025 13:54:34 +0500 Subject: [PATCH] ExtractElements - expose assume_asset_uniqueness_by_name option #6243 I'd much rather not expose this option to ifcpatch but I guess models are different and there should be a way to extract elements even if assets name uniqueness is not ensured (since it's not IFC requirement anyway). But it may cause duplicated assets. --- src/bonsai/bonsai/bim/module/patch/ui.py | 9 +++++-- .../ifcpatch/recipes/ExtractElements.py | 24 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/patch/ui.py b/src/bonsai/bonsai/bim/module/patch/ui.py index 03822642a9..8c165d692f 100644 --- a/src/bonsai/bonsai/bim/module/patch/ui.py +++ b/src/bonsai/bonsai/bim/module/patch/ui.py @@ -16,10 +16,15 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . +from __future__ import annotations import bpy import bonsai.tool as tool from bonsai.bim.helper import prop_with_search from bonsai.bim.helper import draw_attributes +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from bonsai.bim.prop import Attribute class BIM_PT_patch(bpy.types.Panel): @@ -54,8 +59,8 @@ class BIM_PT_patch(bpy.types.Panel): row.prop(props, "ifc_patch_output") row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="") - def draw_callback_(_, row: bpy.types.UILayout) -> None: - if props.ifc_patch_recipes == "ExtractElements": + def draw_callback_(attribute: Attribute, row: bpy.types.UILayout) -> None: + if props.ifc_patch_recipes == "ExtractElements" and attribute.name == "Query": row.operator("bim.patch_query_from_selected", text="", icon="EYEDROPPER") if props.ifc_patch_args_attr: diff --git a/src/ifcpatch/ifcpatch/recipes/ExtractElements.py b/src/ifcpatch/ifcpatch/recipes/ExtractElements.py index 63bb8a298c..b1fee6db2f 100644 --- a/src/ifcpatch/ifcpatch/recipes/ExtractElements.py +++ b/src/ifcpatch/ifcpatch/recipes/ExtractElements.py @@ -26,7 +26,13 @@ from logging import Logger class Patcher: - def __init__(self, file: ifcopenshell.file, logger: Logger, query: str = "IfcWall"): + def __init__( + self, + file: ifcopenshell.file, + logger: Logger, + query: str = "IfcWall", + assume_asset_uniqueness_by_name: bool = True, + ): """Extract certain elements into a new model Extract a subset of elements from an existing IFC data set and save it @@ -34,7 +40,14 @@ class Patcher: in a model and save it as a new model. :param query: A query to select the subset of IFC elements. - :type query: str + :param assume_asset_uniqueness_by_name: Avoid adding assets (profiles, materials, styles) + with the same name multiple times. Which helps in avoiding duplicated assets. + ----- + Note that it assumes different project assets use different names + (you can run IFC Assets Validation to confirm). + If they're not and this option is enabled, it may lead to confusing results + (mixed up profiles, materials, styles). + So either need to ensure assets naming is unique or disable this option. Example: @@ -52,6 +65,7 @@ class Patcher: self.file = file self.logger = logger self.query = query + self.assume_asset_uniqueness_by_name = assume_asset_uniqueness_by_name def patch(self): self.contained_ins: dict[str, set[ifcopenshell.entity_instance]] = {} @@ -83,7 +97,11 @@ class Patcher: if element.is_a("IfcProject"): return self.new.add(element) return ifcopenshell.api.project.append_asset( - self.new, library=self.file, element=element, reuse_identities=self.reuse_identities + self.new, + library=self.file, + element=element, + reuse_identities=self.reuse_identities, + assume_asset_uniqueness_by_name=self.assume_asset_uniqueness_by_name, ) def add_spatial_structures(