From 46b3bfecd14c5878fe9ad3a83b46f5ca0b09f649 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 29 Jul 2024 12:45:41 +0500 Subject: [PATCH] fix issues assigning material sets and material lists --- src/blenderbim/blenderbim/core/material.py | 2 +- src/blenderbim/blenderbim/tool/material.py | 3 ++- src/blenderbim/blenderbim/tool/model.py | 3 ++- .../ifcopenshell/api/material/assign_material.py | 3 +++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/core/material.py b/src/blenderbim/blenderbim/core/material.py index 8c12d2b8c5..fba7082cc1 100644 --- a/src/blenderbim/blenderbim/core/material.py +++ b/src/blenderbim/blenderbim/core/material.py @@ -118,7 +118,6 @@ def assign_material( continue ifc.run("material.assign_material", products=[element], type=material_type, material=material) - material_tool.ensure_material_assigned(elements=[element], material_type=material_type, material=material) assigned_material = material_tool.get_material(element) assert assigned_material # Type checker. @@ -128,6 +127,7 @@ def assign_material( material_tool.add_material_to_set(material_set=material, material=default_material) elif material_tool.is_a_material_set(assigned_material): material_tool.add_material_to_set(material_set=assigned_material, material=material) + material_tool.ensure_material_assigned(elements=[element], material_type=material_type, material=material) def unassign_material(ifc: tool.Ifc, material_tool: tool.Material, objects: list[bpy.types.Object]) -> None: diff --git a/src/blenderbim/blenderbim/tool/material.py b/src/blenderbim/blenderbim/tool/material.py index 790e61a5cd..df57363c74 100644 --- a/src/blenderbim/blenderbim/tool/material.py +++ b/src/blenderbim/blenderbim/tool/material.py @@ -321,7 +321,8 @@ class Material(blenderbim.core.tool.Material): ) -> None: """Ensure blender materials are updated after a material assignment. - Designed to be called after material.assign_material API call.""" + Designed to be called after material.assign_material API call. + For material sets it should be called after some item is already added to the material set.""" # NOTE: adding/editing/removing layers/profiles/constituents is not supported. # Adding support for profiles/layers it only will be possible when we'll be adding styles diff --git a/src/blenderbim/blenderbim/tool/model.py b/src/blenderbim/blenderbim/tool/model.py index 4f79e13a16..46dcc4e6b8 100644 --- a/src/blenderbim/blenderbim/tool/model.py +++ b/src/blenderbim/blenderbim/tool/model.py @@ -1308,7 +1308,8 @@ class Model(blenderbim.core.tool.Model): obj = next(iter(mesh_users)) element = tool.Ifc.get_entity(obj) - own_material = ifcopenshell.util.element.get_material(element, should_inherit=False) + assert element # Type checker. + own_material = next(iter(ifcopenshell.util.element.get_materials(element, should_inherit=False)), None) inherited_mstyle = tool.Geometry.get_inherited_material_style(element) if assigned_material: diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/assign_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/assign_material.py index a9c9caf9f9..7f4259143a 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/assign_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/assign_material.py @@ -74,6 +74,9 @@ def assign_material( :param material: The IfcMaterial or material set you are assigning here. If type is Usage then no need to provide `material`, it will be deduced from the element type automatically. + If IfcMaterial is provided as material and type is not IfcMaterial, + provided material will be ignored except for IfcMaterialList + where it will be used as part of the list. :type material: ifcopenshell.entity_instance, optional :return: IfcRelAssociatesMaterial entity or a list of IfcRelAssociatesMaterial entities