From 05f7ffcbccdcce0a17654089225e3fbe4417ff15 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Thu, 25 Dec 2025 18:32:03 -0600 Subject: [PATCH] fix #6682: avoid applying styles directly to geometry when inherited from material When duplicating elements, skip assign_body_styles if the element's constituent materials already have style representations. This prevents creating redundant IfcStyledItem entities on the geometry when styles should be inherited from the material definition. --- src/bonsai/bonsai/core/root.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/core/root.py b/src/bonsai/bonsai/core/root.py index d43c20a343..957298c044 100644 --- a/src/bonsai/bonsai/core/root.py +++ b/src/bonsai/bonsai/core/root.py @@ -18,6 +18,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional +import ifcopenshell.util.element if TYPE_CHECKING: import bpy @@ -53,11 +54,32 @@ def copy_class( geometry.copy_data_links(data, copied_entities) geometry.change_object_data(obj, data, is_global=True) geometry.rename_object(data, geometry.get_representation_name(ifc.get_entity(data))) - root.assign_body_styles(new, obj) + # Only assign styles if element doesn't get them from material + if not _has_material_styles(ifc, new): + root.assign_body_styles(new, obj) collector.assign(obj) return new +def _has_material_styles(ifc: type[tool.Ifc], element: ifcopenshell.entity_instance) -> bool: + """Check if element has styles defined through its material. + + Returns True if any constituent material has a style representation, + which means styles should NOT be applied directly to the geometry. + """ + materials = ifcopenshell.util.element.get_materials(element) + + if not materials: + return False + + # Check if any of the constituent materials have styles + for material in materials: + if hasattr(material, 'HasRepresentation') and material.HasRepresentation: + return True + + return False + + def assign_class( ifc: type[tool.Ifc], collector: type[tool.Collector],