New support for sorting IfcCSV outputs

This commit is contained in:
Dion Moult
2023-08-22 14:32:26 +10:00
parent 4838b13d63
commit 83566845df
4 changed files with 58 additions and 23 deletions
@@ -76,10 +76,11 @@ class ImportCsvAttributes(bpy.types.Operator):
tool.Search.import_filter_query(data["query"], props.filter_groups)
props.csv_attributes.clear()
for i, attribute in enumerate(data["attributes"]):
for attribute in data["attributes"]:
new = props.csv_attributes.add()
new.name = attribute
new.header = data["headers"][i]
new.name = attribute["name"]
new.header = attribute["header"]
new.sort = attribute["sort"]
return {"FINISHED"}
def invoke(self, context, event):
@@ -101,8 +102,7 @@ class ExportCsvAttributes(bpy.types.Operator):
data = {
"query": tool.Search.export_filter_query(props.filter_groups),
"attributes": [a.name for a in props.csv_attributes],
"headers": [a.header for a in props.csv_attributes],
"attributes": [{"name": a.name, "header": a.header, "sort": a.sort} for a in props.csv_attributes],
}
with open(self.filepath, "w") as outfile:
@@ -146,6 +146,12 @@ class ExportIfcCsv(bpy.types.Operator):
ifc_csv = ifccsv.IfcCsv()
attributes = [a.name for a in props.csv_attributes]
headers = [a.header for a in props.csv_attributes]
sort = []
for attribute in props.csv_attributes:
if attribute.sort != "NONE":
sort.append({"name": attribute.name, "order": attribute.sort})
sep = props.csv_custom_delimiter if props.csv_delimiter == "CUSTOM" else props.csv_delimiter
ifc_csv.export(
ifc_file,
@@ -160,6 +166,7 @@ class ExportIfcCsv(bpy.types.Operator):
null=props.null_value,
bool_true=props.true_value,
bool_false=props.false_value,
sort=sort,
)
return {"FINISHED"}
@@ -35,6 +35,7 @@ from bpy.props import (
class CsvAttribute(PropertyGroup):
name: StringProperty(name="Query", default="class")
header: StringProperty(name="Header Value", default="IFC Class")
sort: EnumProperty(items=[("NONE", "None", ""), ("ASC", "Ascending", ""), ("DESC", "Descending", "")])
class CsvProperties(PropertyGroup):
@@ -80,4 +81,5 @@ class CsvProperties(PropertyGroup):
)
csv_custom_delimiter: StringProperty(default="", name="Custom Delimiter")
should_show_settings: BoolProperty(default=False, name="Show Settings")
should_show_sort: BoolProperty(default=False, name="Show Sort")
should_load_from_memory: BoolProperty(default=False, name="Load from Memory")
@@ -42,13 +42,13 @@ class BIM_PT_ifccsv(Panel):
row.prop(props, "should_load_from_memory")
row.operator("bim.import_csv_attributes", icon="IMPORT", text="")
row.operator("bim.export_csv_attributes", icon="EXPORT", text="")
row.prop(props, "should_show_settings", icon="PREFERENCES", text="")
else:
row = layout.row(align=True)
row.alignment = "RIGHT"
row.operator("bim.import_csv_attributes", icon="IMPORT", text="")
row.operator("bim.export_csv_attributes", icon="EXPORT", text="")
row.prop(props, "should_show_settings", icon="PREFERENCES", text="")
row.prop(props, "should_show_sort", icon="SORTSIZE", text="")
row.prop(props, "should_show_settings", icon="PREFERENCES", text="")
if not IfcStore.get_file() or not props.should_load_from_memory:
row = layout.row(align=True)
@@ -88,7 +88,10 @@ class BIM_PT_ifccsv(Panel):
for index, attribute in enumerate(props.csv_attributes):
row = layout.row(align=True)
row.prop(attribute, "name", text="")
row.prop(attribute, "header", text="")
if props.should_show_sort:
row.prop(attribute, "sort", text="")
else:
row.prop(attribute, "header", text="")
row.operator("bim.remove_csv_attribute", icon="X", text="").index = index
row = layout.row(align=True)