New UI to manage material psets instead of needing to use CSVs

This commit is contained in:
Dion Moult
2020-11-11 23:02:07 +11:00
parent d6397baa59
commit 808ef1a19e
6 changed files with 45 additions and 53 deletions
@@ -1 +0,0 @@
MassDensity,7.8
1 MassDensity 7.8
@@ -1,2 +0,0 @@
YoungModulus,210000000
PoissonRatio,0.2
1 YoungModulus 210000000
2 PoissonRatio 0.2
@@ -43,6 +43,7 @@ class IfcParser:
self.people = []
self.organisations = []
self.psets = {}
self.material_psets = {}
self.document_references = {}
self.classifications = []
self.classification_references = {}
@@ -100,7 +101,6 @@ class IfcParser:
selected_objects = self.add_spatial_elements_if_unselected(selected_objects)
self.add_type_elements_if_unselected(selected_objects)
self.categorise_selected_objects(selected_objects)
self.material_psets = self.get_material_psets()
self.document_information = self.get_document_information()
self.document_references = self.get_document_references()
self.classifications = self.get_classifications()
@@ -458,6 +458,16 @@ class IfcParser:
results[item_key] = {"ifc": None, "raw": raw, "attributes": {"Name": item.name}}
relationships.setdefault(item_key, []).append(product)
def get_material_psets(self, material, obj):
psets = obj.BIMMaterialProperties.psets
results = self.material_psets
for item in psets:
item_key = "{}/{}".format(item.name, obj.name)
raw = {p.name: p.string_value for p in item.properties if p.string_value}
if not raw:
continue
results[item_key] = {"ifc": None, "raw": raw, "material": material, "attributes": {"Name": item.name}}
def add_automatic_qtos(self, ifc_class, obj):
if not obj.data:
return
@@ -583,21 +593,6 @@ class IfcParser:
elif not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
self.selected_products.append({"raw": obj, "metadata": metadata})
def get_material_psets(self):
psets = {}
for filename in Path(self.data_dir + "material/").glob("**/*.csv"):
with open(filename, "r") as f:
description = filename.parts[-2]
name = filename.stem
if description not in psets:
psets[description] = {}
psets[description][name] = {
"ifc": None,
"raw": {x[0]: x[1] for x in list(csv.reader(f))},
"attributes": {"Name": name, "Description": description},
}
return psets
def get_door_attributes(self):
return self.get_predefined_attributes("door")
@@ -1151,11 +1146,13 @@ class IfcParser:
continue
if slot.material.name in results or slot.link == "OBJECT":
continue
results[slot.material.name] = {
material = {
"ifc": None,
"raw": slot.material,
"attributes": self.get_material_attributes(slot.material),
}
results[slot.material.name] = material
self.get_material_psets(material, slot.material)
return results
def get_material_attributes(self, material):
@@ -1648,17 +1645,13 @@ class IfcExporter:
pset["ifc"] = self.file.create_entity("IfcPropertySet", **pset["attributes"])
def create_material_psets(self, material):
for pset_dir in material["raw"].BIMMaterialProperties.psets:
for name, properties in self.ifc_parser.material_psets[pset_dir.name].items():
self.file.create_entity(
"IfcMaterialProperties",
**{
"Name": name,
"Description": pset_dir.name,
"Properties": self.create_pset_properties(properties),
"Material": material["ifc"],
},
)
for pset in self.ifc_parser.material_psets.values():
properties = self.create_pset_properties(pset)
if not properties:
continue
pset["attributes"].update({"Properties": properties, "Material": pset["material"]["ifc"]})
print(pset["attributes"])
pset["ifc"] = self.file.create_entity("IfcMaterialProperties", **pset["attributes"])
def create_qto_properties(self, qto):
if qto["attributes"]["Name"] in ifcopenshell.util.pset.qtos:
@@ -943,8 +943,17 @@ class AddMaterialPset(bpy.types.Operator):
bl_label = "Add Material Pset"
def execute(self, context):
pset = bpy.context.active_object.active_material.BIMMaterialProperties.psets.add()
pset.name = bpy.context.active_object.active_material.BIMMaterialProperties.available_material_psets
material = bpy.context.active_object.active_material
name = material.BIMMaterialProperties.pset_name
if name not in ifcopenshell.util.pset.psets:
return {"FINISHED"}
if material.BIMMaterialProperties.psets.find(name) != -1:
return {"FINISHED"}
pset = material.BIMMaterialProperties.psets.add()
pset.name = name
for prop_name in ifcopenshell.util.pset.psets[name]["HasPropertyTemplates"].keys():
prop = pset.properties.add()
prop.name = prop_name
return {"FINISHED"}
+12 -11
View File
@@ -35,7 +35,7 @@ ifcpatchrecipes_enum = []
featuresfiles_enum = []
titleblocks_enum = []
scenarios_enum = []
psetnames_enum = []
materialpsetnames_enum = []
psetfiles_enum = []
psettemplatefiles_enum = []
propertysettemplates_enum = []
@@ -312,15 +312,6 @@ def getOrganisations(self, context):
return organisations_enum
def getAvailableMaterialPsets(self, context):
global availablematerialpsets_enum
if len(availablematerialpsets_enum) < 1:
availablematerialpsets_enum.clear()
files = os.listdir(os.path.join(context.scene.BIMProperties.data_dir, "material"))
availablematerialpsets_enum.extend([(f, f, "") for f in files])
return availablematerialpsets_enum
def getIfcPatchRecipes(self, context):
global ifcpatchrecipes_enum
if len(ifcpatchrecipes_enum) < 1:
@@ -441,6 +432,16 @@ def getPsetNames(self, context):
return psetnames_enum
def getMaterialPsetNames(self, context):
global materialpsetnames_enum
materialpsetnames_enum.clear()
pset_names = ifcopenshell.util.pset.get_applicable_psetqtos(
bpy.context.scene.BIMProperties.export_schema, "IfcMaterial", is_pset=True
)
materialpsetnames_enum.extend([(p, p, "") for p in pset_names])
return materialpsetnames_enum
def getQtoNames(self, context):
global qtonames_enum
qtonames_enum.clear()
@@ -1693,7 +1694,7 @@ class BIMMaterialProperties(PropertyGroup):
location: StringProperty(name="Location")
identification: StringProperty(name="Identification")
name: StringProperty(name="Name")
available_material_psets: EnumProperty(items=getAvailableMaterialPsets, name="Material Pset")
pset_name: EnumProperty(items=getMaterialPsetNames, name="Pset Name")
psets: CollectionProperty(name="Psets", type=PsetQto)
attributes: CollectionProperty(name="Attributes", type=Attribute)
applicable_attributes: EnumProperty(items=getApplicableMaterialAttributes, name="Attribute Names")
+1 -9
View File
@@ -849,25 +849,17 @@ class BIM_PT_material(Panel):
layout.label(text="Property Sets:")
row = layout.row(align=True)
row.prop(props, "available_material_psets", text="")
row.prop(props, "pset_name", text="")
row.operator("bim.add_material_pset")
for index, pset in enumerate(props.psets):
row = layout.row(align=True)
row.prop(pset, "name", text="")
row.operator("bim.remove_material_pset", icon="X", text="").pset_index = index
op = row.operator("bim.copy_property_to_selection", icon="COPYDOWN", text="")
for prop in pset.properties:
row = layout.row(align=True)
row.prop(prop, "name", text="")
row.prop(prop, "string_value", text="")
op = row.operator("bim.copy_property_to_selection", icon="COPYDOWN", text="")
op.pset_name = pset.name
op.prop_name = prop.name
op.prop_value = prop.string_value
row = layout.row()
row.prop(props, "psets", text="")
class BIM_PT_gis(Panel):