Move material psets to material manager.

This commit is contained in:
Dion Moult
2024-05-26 09:59:01 +10:00
parent dac9bfe3d4
commit 80d31b4e1a
6 changed files with 34 additions and 31 deletions
@@ -64,9 +64,9 @@ classes = (
def register():
bpy.types.Object.PsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Scene.MaterialPsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Object.MaterialSetPsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Object.MaterialSetItemPsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Material.PsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Scene.TaskPsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Scene.ResourcePsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
bpy.types.Scene.GroupPsetProperties = bpy.props.PointerProperty(type=prop.PsetProperties)
@@ -79,7 +79,9 @@ def register():
def unregister():
del bpy.types.Object.PsetProperties
del bpy.types.Material.PsetProperties
del bpy.types.Object.MaterialPsetProperties
del bpy.types.Object.MaterialSetPsetProperties
del bpy.types.Object.MaterialSetItemPsetProperties
del bpy.types.Scene.TaskPsetProperties
del bpy.types.Scene.ResourcePsetProperties
del bpy.types.Scene.GroupPsetProperties
@@ -157,9 +157,14 @@ class MaterialPsetsData(Data):
@classmethod
def load(cls):
ifc_definition_id = None
props = bpy.context.scene.BIMMaterialProperties
if props.materials and props.active_material_index < len(props.materials):
ifc_definition_id = props.materials[props.active_material_index].ifc_definition_id
cls.data = {
"ifc_definition_id": bpy.context.active_object.active_material.BIMObjectProperties.ifc_definition_id,
"psets": cls.psetqtos(tool.Ifc.get_entity(bpy.context.active_object.active_material)),
"ifc_definition_id": ifc_definition_id,
"psets": cls.psetqtos(tool.Ifc.get().by_id(ifc_definition_id)),
}
cls.is_loaded = True
@@ -69,7 +69,7 @@ def get_pset_name(self, context):
results = get_material_set_pset_names(self, context)
elif prop_type == "MaterialSetItemPsetProperties":
results = get_material_set_item_pset_names(self, context)
elif "bpy.data.materials" in pset_type:
elif prop_type == "MaterialPsetProperties":
results = get_material_pset_names(self, context)
elif prop_type == "ResourcePsetProperties":
results = get_resource_pset_names(self, context)
+18 -24
View File
@@ -79,13 +79,7 @@ def draw_enumerated_property(prop, layout, copy_operator=None):
def get_active_pset_obj_name(context, obj_type):
if obj_type == "Object":
return context.active_object.name
elif obj_type == "Material":
return context.active_object.active_material.name
elif obj_type == "MaterialSet":
return context.active_object.name
elif obj_type == "MaterialSetItem":
if obj_type in ("Object", "Material", "MaterialSet", "MaterialSetItem"):
return context.active_object.name
return ""
@@ -286,36 +280,36 @@ class BIM_PT_material_psets(Panel):
bl_idname = "BIM_PT_material_psets"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "material"
bl_context = "scene"
bl_parent_id = "BIM_PT_materials"
@classmethod
def poll(cls, context):
if not context.active_object:
return False
if not context.active_object.active_material:
return False
props = context.active_object.active_material.BIMObjectProperties
if not props.ifc_definition_id:
return False
file = IfcStore.get_file()
if not file or file.schema == "IFC2X3":
ifc_file = tool.Ifc.get()
if not ifc_file or ifc_file.schema == "IFC2X3":
return False # We don't support material psets in IFC2X3 because they suck
return True
props = context.scene.BIMMaterialProperties
if props.materials and props.active_material_index < len(props.materials):
material = props.materials[props.active_material_index]
if material.ifc_definition_id:
return True
return False
def draw(self, context):
props = context.scene.BIMMaterialProperties
if props.materials and props.active_material_index < len(props.materials):
ifc_definition_id = props.materials[props.active_material_index].ifc_definition_id
if not MaterialPsetsData.is_loaded:
MaterialPsetsData.load()
elif (
context.active_object.active_material.BIMObjectProperties.ifc_definition_id
!= MaterialPsetsData.data["ifc_definition_id"]
):
elif ifc_definition_id != MaterialPsetsData.data["ifc_definition_id"]:
MaterialPsetsData.load()
props = context.active_object.active_material.PsetProperties
props = context.scene.MaterialPsetProperties
row = self.layout.row(align=True)
prop_with_search(row, props, "pset_name", text="")
op = row.operator("bim.add_pset", icon="ADD", text="")
op.obj = context.active_object.active_material.name
op.obj = context.active_object.name
op.obj_type = "Material"
if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "PSET":
+3 -1
View File
@@ -144,7 +144,9 @@ class Blender(blenderbim.core.tool.Blender):
if obj_type == "Object":
return bpy.data.objects.get(obj).BIMObjectProperties.ifc_definition_id
elif obj_type == "Material":
return bpy.data.materials.get(obj).BIMObjectProperties.ifc_definition_id
return context.scene.BIMMaterialProperties.materials[
context.scene.BIMMaterialProperties.active_material_index
].ifc_definition_id
elif obj_type == "MaterialSet":
return ifcopenshell.util.element.get_material(
tool.Ifc.get_entity(bpy.data.objects.get(obj)), should_skip_usage=True
+1 -1
View File
@@ -40,7 +40,7 @@ class Pset(blenderbim.core.tool.Pset):
if obj_type == "Object":
return bpy.data.objects.get(obj).PsetProperties
elif obj_type == "Material":
return bpy.data.materials.get(obj).PsetProperties
return bpy.context.scene.MaterialPsetProperties
elif obj_type == "MaterialSet":
return bpy.data.objects.get(obj).MaterialSetPsetProperties
elif obj_type == "MaterialSetItem":