bim.duplicate_material to handle IfcMaterialLayerSets names

This commit is contained in:
Andrej730
2024-07-05 15:03:34 +05:00
parent 0557ff810a
commit d0f4c25c9f
3 changed files with 15 additions and 6 deletions
@@ -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()
@@ -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
@@ -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