From d0f4c25c9fd44584879dcbc6b8c3e58b1c4d5e41 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 5 Jul 2024 15:03:34 +0500 Subject: [PATCH] bim.duplicate_material to handle IfcMaterialLayerSets names --- .../blenderbim/bim/module/material/operator.py | 7 +------ src/blenderbim/blenderbim/tool/material.py | 13 +++++++++++++ src/blenderbim/blenderbim/tool/profile.py | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index 04dd5bbffd..28cfef9dfa 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -146,12 +146,7 @@ class DuplicateMaterial(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): material = tool.Ifc.get().by_id(self.material) - new = tool.Ifc.run("material.copy_material", material=material) - - if not new.is_a("IfcMaterialList"): - name = new[0] + " Copy" - new[0] = name - + tool.Material.duplicate_material(material) material_prop_purge() bpy.ops.bim.load_materials() diff --git a/src/blenderbim/blenderbim/tool/material.py b/src/blenderbim/blenderbim/tool/material.py index 89ce7f4db6..f62fbae248 100644 --- a/src/blenderbim/blenderbim/tool/material.py +++ b/src/blenderbim/blenderbim/tool/material.py @@ -38,6 +38,19 @@ class Material(blenderbim.core.tool.Material): def disable_editing_materials(cls) -> None: bpy.context.scene.BIMMaterialProperties.is_editing = False + @classmethod + def duplicate_material(cls, material: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + new = tool.Ifc.run("material.copy_material", material=material) + + # Doesn't have a name. + if new.is_a("IfcMaterialList"): + return new + + name_index = 1 if new.is_a("IfcMaterialLayerSet") else 0 + name = (new[name_index] or "Unnamed") + " Copy" + new[name_index] = name + return new + @classmethod def enable_editing_materials(cls) -> None: bpy.context.scene.BIMMaterialProperties.is_editing = True diff --git a/src/blenderbim/blenderbim/tool/profile.py b/src/blenderbim/blenderbim/tool/profile.py index fded9d2ab3..cc2bb50b19 100644 --- a/src/blenderbim/blenderbim/tool/profile.py +++ b/src/blenderbim/blenderbim/tool/profile.py @@ -85,5 +85,6 @@ class Profile(blenderbim.core.tool.Profile): @classmethod def duplicate_profile(cls, profile: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: new_profile = ifcopenshell.util.element.copy_deep(tool.Ifc.get(), profile) + # In UI unnamed profiles are not available, so we don't handle them. new_profile.ProfileName = profile.ProfileName + "_copy" return new_profile