mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
fix console errors related to material rename from ui
1) update_material_name was triggered for categories and failed since ifc id in that case = 0 2) update_material_name was triggered for materials when they were still incomplete and ifc id was still 0 3) moved setting material.name before settings ifc_id to avoid triggering unnecessary changes in ifc
This commit is contained in:
@@ -120,6 +120,11 @@ def get_contexts(self, context):
|
||||
|
||||
|
||||
def update_material_name(self: "Material", context: bpy.types.Context) -> None:
|
||||
# No need to update anything if it's either category
|
||||
# or ifc_definition_id is not yet set
|
||||
# (which occurs when Material still in the process of creation).
|
||||
if self.is_category or not self.ifc_definition_id:
|
||||
return
|
||||
ifc_file = tool.Ifc.get()
|
||||
name = self.name
|
||||
material = ifc_file.by_id(self.ifc_definition_id)
|
||||
|
||||
@@ -92,6 +92,7 @@ class Material(blenderbim.core.tool.Material):
|
||||
get_name = lambda x: "Unnamed"
|
||||
materials = sorted(tool.Ifc.get().by_type(material_type), key=get_name)
|
||||
categories = defaultdict(list)
|
||||
|
||||
if material_type == "IfcMaterial":
|
||||
category_index_to_reselect = None
|
||||
|
||||
@@ -112,8 +113,9 @@ class Material(blenderbim.core.tool.Material):
|
||||
|
||||
for material in mats if cat.is_expanded else []:
|
||||
new = props.materials.add()
|
||||
new.ifc_definition_id = material.id()
|
||||
# Assign name before assigning ifc_definition_id to avoid triggering IFC update.
|
||||
new.name = get_name(material)
|
||||
new.ifc_definition_id = material.id()
|
||||
new.total_elements = len(
|
||||
ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material)
|
||||
)
|
||||
@@ -124,8 +126,9 @@ class Material(blenderbim.core.tool.Material):
|
||||
return
|
||||
for material in materials:
|
||||
new = props.materials.add()
|
||||
new.ifc_definition_id = material.id()
|
||||
# Assign name before assigning ifc_definition_id to avoid triggering IFC update.
|
||||
new.name = get_name(material)
|
||||
new.ifc_definition_id = material.id()
|
||||
new.total_elements = len(ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material))
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user