You can now reorder columns in IfcCSV

This commit is contained in:
Dion Moult
2023-08-24 13:56:43 +10:00
parent c190ae5aea
commit 6b05f4a2aa
3 changed files with 35 additions and 6 deletions
@@ -21,13 +21,14 @@ from . import ui, prop, operator
classes = (
operator.AddCsvAttribute,
operator.RemoveCsvAttribute,
operator.RemoveAllCsvAttributes,
operator.ExportIfcCsv,
operator.ImportIfcCsv,
operator.SelectCsvIfcFile,
operator.ImportCsvAttributes,
operator.ExportCsvAttributes,
operator.ExportIfcCsv,
operator.ImportCsvAttributes,
operator.ImportIfcCsv,
operator.RemoveAllCsvAttributes,
operator.RemoveCsvAttribute,
operator.ReorderCsvAttribute,
operator.SelectCsvIfcFile,
prop.CsvAttribute,
prop.CsvProperties,
ui.BIM_PT_ifccsv,
@@ -62,6 +62,24 @@ class RemoveAllCsvAttributes(bpy.types.Operator):
return {"FINISHED"}
class ReorderCsvAttribute(bpy.types.Operator):
bl_idname = "bim.reorder_csv_attribute"
bl_label = "Reorder CSV Attribute"
bl_options = {"REGISTER", "UNDO"}
old_index: bpy.props.IntProperty()
new_index: bpy.props.IntProperty()
def execute(self, context):
old = context.scene.CsvProperties.csv_attributes[self.old_index]
new = context.scene.CsvProperties.csv_attributes[self.new_index]
props = ["name", "header", "sort", "group", "varies_value", "summary"]
for prop in props:
value = getattr(new, prop)
setattr(new, prop, getattr(old, prop))
setattr(old, prop, value)
return {"FINISHED"}
class ImportCsvAttributes(bpy.types.Operator):
bl_idname = "bim.import_csv_attributes"
bl_label = "Load CSV Settings"
@@ -87,6 +87,7 @@ class BIM_PT_ifccsv(Panel):
row.prop(props, "should_show_group", icon="OUTLINER_COLLECTION", text="")
row.prop(props, "should_show_summary", icon="SYNTAX_ON", text="")
total = len(props.csv_attributes)
for index, attribute in enumerate(props.csv_attributes):
row = layout.row(align=True)
row.prop(attribute, "name", text="")
@@ -99,6 +100,15 @@ class BIM_PT_ifccsv(Panel):
row.prop(attribute, "varies_value", text="")
if props.should_show_summary:
row.prop(attribute, "summary", text="")
if total > 1:
if index != 0:
op = row.operator(f"bim.reorder_csv_attribute", icon="TRIA_UP", text="")
op.old_index = index
op.new_index = index - 1
if index + 1 != total:
op = row.operator(f"bim.reorder_csv_attribute", icon="TRIA_DOWN", text="")
op.old_index = index
op.new_index = index + 1
row.operator("bim.remove_csv_attribute", icon="X", text="").index = index
row = layout.row(align=True)