From bbca07d53523ad9d49d59ea73aa643cc25b44bfa Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 6 Nov 2024 17:50:27 +0500 Subject: [PATCH] Edit other representation item attributes besides IfcSweptSolid depth Examples: - https://imgchest.com/p/qb4zjgbklyj - https://imgchest.com/p/lqye68r2k4d Added this feature in a very experiment way, I'm sure it will break very soon and we'll be able to refine it. --- .../bonsai/bim/module/geometry/operator.py | 6 +----- .../bonsai/bim/module/model/workspace.py | 4 ++-- src/bonsai/bonsai/tool/geometry.py | 21 ++++++++++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 8b6f13cde0..f41a7c7edc 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2582,11 +2582,7 @@ class UpdateItemAttributes(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = context.active_object - props = obj.data.BIMMeshProperties - item = tool.Ifc.get().by_id(props.ifc_definition_id) - for attribute in props.item_attributes: - if attribute.name == "Depth": - item.Depth = attribute.float_value + tool.Geometry.update_item_attributes(obj) tool.Geometry.reload_representation(bpy.context.scene.BIMGeometryProperties.representation_obj) tool.Geometry.import_item(obj) tool.Root.reload_item_decorator() diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index b45719b283..9348922584 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -24,7 +24,7 @@ import bonsai.bim import bonsai.tool as tool import bonsai.core.model as core from bonsai.bim.module.model.wall import DumbWallJoiner -from bonsai.bim.helper import prop_with_search +from bonsai.bim.helper import prop_with_search, draw_attribute from bpy.types import WorkSpaceTool, Menu from bonsai.bim.module.model.data import AuthoringData, ItemData from bonsai.bim.module.system.data import PortData @@ -278,7 +278,7 @@ class EditItemUI: assert obj for item_attribute in obj.data.BIMMeshProperties.item_attributes: row = cls.layout.row() - row.prop(item_attribute, item_attribute.get_value_name(display_only=True), text=item_attribute.name) + draw_attribute(item_attribute, cls.layout) if len(obj.data.BIMMeshProperties.item_attributes): row = cls.layout.row() row.operator("bim.update_item_attributes", icon="FILE_REFRESH", text="") diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index c5f94b8486..75c2a89fa5 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -1539,12 +1539,27 @@ class Geometry(bonsai.core.tool.Geometry): props = obj.data.BIMMeshProperties props.item_attributes.clear() item = tool.Ifc.get().by_id(props.ifc_definition_id) - if item.is_a("IfcExtrudedAreaSolid"): + attributes = item.wrapped_data.declaration().as_entity().all_attributes() + for attribute in attributes: + if not attribute.type_of_attribute()._is("IfcLengthMeasure"): + continue new: Attribute = props.item_attributes.add() - new.name = "Depth" + attr_name = attribute.name() + new.name = attr_name new.data_type = "float" new.special_type = "LENGTH" - new.float_value = item.Depth + value = getattr(item, attr_name) + is_null = value is None + new.is_null = is_null + new.float_value = 0.0 if is_null else value + new.is_optional = attribute.optional() + + @classmethod + def update_item_attributes(cls, obj: bpy.types.Object) -> None: + props = obj.data.BIMMeshProperties + item = tool.Ifc.get().by_id(props.ifc_definition_id) + for attribute in props.item_attributes: + setattr(item, attribute.name, attribute.get_value()) @classmethod def import_item(cls, obj: bpy.types.Object) -> None: