diff --git a/src/blenderbim/blenderbim/bim/module/material/data.py b/src/blenderbim/blenderbim/bim/module/material/data.py index 69015b1390..ee2aba7826 100644 --- a/src/blenderbim/blenderbim/bim/module/material/data.py +++ b/src/blenderbim/blenderbim/bim/module/material/data.py @@ -36,31 +36,17 @@ class MaterialsData: @classmethod def load(cls): - cls.data = { - "total_materials": cls.total_materials(), - "material_types": cls.material_types(), - "profiles": cls.profiles(), - "styles": cls.styles(), - "contexts": cls.contexts(), - "active_styles": cls.active_styles(), - } cls.is_loaded = True + cls.data["material_types"] = cls.material_types() + cls.data["total_materials"] = cls.total_materials() + cls.data["profiles"] = cls.profiles() + cls.data["styles"] = cls.styles() + cls.data["contexts"] = cls.contexts() + cls.data["active_styles"] = cls.active_styles() @classmethod def total_materials(cls): - if tool.Ifc.get_schema() == "IFC2X3": - return ( - len(tool.Ifc.get().by_type("IfcMaterial")) - + len(tool.Ifc.get().by_type("IfcMaterialLayerSet")) - + len(tool.Ifc.get().by_type("IfcMaterialList")) - ) - return ( - len(tool.Ifc.get().by_type("IfcMaterial")) - + len(tool.Ifc.get().by_type("IfcMaterialConstituentSet")) - + len(tool.Ifc.get().by_type("IfcMaterialLayerSet")) - + len(tool.Ifc.get().by_type("IfcMaterialProfileSet")) - + len(tool.Ifc.get().by_type("IfcMaterialList")) - ) + return len(tool.Ifc.get().by_type(bpy.context.scene.BIMMaterialProperties.material_type)) @classmethod def material_types(cls): diff --git a/src/blenderbim/blenderbim/bim/module/material/prop.py b/src/blenderbim/blenderbim/bim/module/material/prop.py index f414a8138e..9374ac67cf 100644 --- a/src/blenderbim/blenderbim/bim/module/material/prop.py +++ b/src/blenderbim/blenderbim/bim/module/material/prop.py @@ -97,6 +97,10 @@ def get_material_types(self, context): return MaterialsData.data["material_types"] +def update_material_type(self, context): + MaterialsData.data["total_materials"] = MaterialsData.total_materials() + + def get_profiles(self, context): if not MaterialsData.is_loaded: MaterialsData.load() @@ -126,7 +130,7 @@ class Material(PropertyGroup): class BIMMaterialProperties(PropertyGroup): is_editing: BoolProperty(name="Is Editing", default=False) - material_type: EnumProperty(items=get_material_types, name="Material Type") + material_type: EnumProperty(items=get_material_types, update=update_material_type, name="Material Type") materials: CollectionProperty(name="Materials", type=Material) active_material_index: IntProperty(name="Active Material Index") profiles: EnumProperty(items=get_profiles, name="Profiles") diff --git a/src/blenderbim/blenderbim/bim/module/material/ui.py b/src/blenderbim/blenderbim/bim/module/material/ui.py index c5ee393d8b..958c778cc4 100644 --- a/src/blenderbim/blenderbim/bim/module/material/ui.py +++ b/src/blenderbim/blenderbim/bim/module/material/ui.py @@ -45,7 +45,7 @@ class BIM_PT_materials(Panel): self.props = context.scene.BIMMaterialProperties row = self.layout.row(align=True) - row.label(text="{} Materials".format(MaterialsData.data["total_materials"]), icon="NODE_MATERIAL") + row.label(text=f"{MaterialsData.data['total_materials']} Materials", icon="NODE_MATERIAL") if self.props.is_editing: row.operator("bim.disable_editing_materials", text="", icon="CANCEL") else: