added new functionality and adjusted UI (#1771)

This commit is contained in:
Vukas Pajic
2021-10-09 01:13:10 +02:00
committed by GitHub
parent d39e97f6a7
commit 84fc198bbe
3 changed files with 80 additions and 5 deletions
@@ -22,10 +22,13 @@ from . import ui, prop, operator
classes = ( classes = (
operator.AddCsvAttribute, operator.AddCsvAttribute,
operator.RemoveCsvAttribute, operator.RemoveCsvAttribute,
operator.RemoveAllCsvAttributes,
operator.ExportIfcCsv, operator.ExportIfcCsv,
operator.ImportIfcCsv, operator.ImportIfcCsv,
operator.EyedropIfcCsv, operator.EyedropIfcCsv,
operator.SelectCsvIfcFile, operator.SelectCsvIfcFile,
operator.ImportCsvAttributes,
operator.ExportCsvAttributes,
prop.CsvProperties, prop.CsvProperties,
ui.BIM_PT_ifccsv, ui.BIM_PT_ifccsv,
) )
@@ -48,6 +48,61 @@ class RemoveCsvAttribute(bpy.types.Operator):
context.scene.CsvProperties.csv_attributes.remove(self.index) context.scene.CsvProperties.csv_attributes.remove(self.index)
return {"FINISHED"} return {"FINISHED"}
class RemoveAllCsvAttributes(bpy.types.Operator):
bl_idname = "bim.remove_all_csv_attributes"
bl_label = "Remove all CSV Attributes"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
context.scene.CsvProperties.csv_attributes.clear()
return {"FINISHED"}
class ImportCsvAttributes(bpy.types.Operator):
bl_idname = "bim.import_csv_attributes"
bl_label = "Import CSV Attributes"
bl_options = {"REGISTER", "UNDO"}
filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"})
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
csv_attributes = context.scene.CsvProperties.csv_attributes
csv_attributes.clear()
csv_json = json.load(open(self.filepath))
i = 0
for attribute in csv_json:
csv_attributes.add()
csv_attributes[i].name = attribute
i +=1
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
class ExportCsvAttributes(bpy.types.Operator):
bl_idname = "bim.export_csv_attributes"
bl_label = "Export CSV Attributes"
bl_options = {"REGISTER", "UNDO"}
filename_ext = ".json"
filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"})
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
csv_attributes = []
with open(self.filepath, "w") as outfile:
for attribute in context.scene.CsvProperties.csv_attributes:
csv_attributes.append(attribute.name)
json.dump(csv_attributes, outfile)
return {"FINISHED"}
def invoke(self, context, event):
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".json")
WindowManager = context.window_manager
WindowManager.fileselect_add(self)
return {"RUNNING_MODAL"}
class ExportIfcCsv(bpy.types.Operator): class ExportIfcCsv(bpy.types.Operator):
bl_idname = "bim.export_ifccsv" bl_idname = "bim.export_ifccsv"
+21 -4
View File
@@ -46,15 +46,29 @@ class BIM_PT_ifccsv(Panel):
row = layout.row(align=True) row = layout.row(align=True)
row.prop(props, "ifc_selector") row.prop(props, "ifc_selector")
row.operator("bim.eyedrop_ifccsv", icon="EYEDROPPER", text="") row.operator("bim.eyedrop_ifccsv", icon="EYEDROPPER", text="")
layout.separator()
row = layout.row() row = layout.row()
row.operator("bim.add_csv_attribute") split = row.split(factor=0.7)
c = split.column()
c.operator("bim.add_csv_attribute")
c = split.column()
c.operator("bim.import_csv_attributes", icon="IMPORT", text="Load Template")
for index, attribute in enumerate(props.csv_attributes): for index, attribute in enumerate(props.csv_attributes):
row = layout.row(align=True) row = layout.row(align=True)
row.prop(attribute, "name", text="") row.prop(attribute, "name", text="")
row.operator("bim.remove_csv_attribute", icon="X", text="").index = index row.operator("bim.remove_csv_attribute", icon="X", text="").index = index
if props.csv_attributes:
row = layout.row()
row.label()
row.operator("bim.remove_all_csv_attributes", icon="CANCEL", text="")
row = layout.row()
row.operator("bim.export_csv_attributes", icon="EXPORT", text="Create Template")
layout.separator()
row = layout.row(align=True) row = layout.row(align=True)
row.prop(props, "csv_delimiter") row.prop(props, "csv_delimiter")
@@ -62,6 +76,9 @@ class BIM_PT_ifccsv(Panel):
row = layout.row(align=True) row = layout.row(align=True)
row.prop(props, "csv_custom_delimiter") row.prop(props, "csv_custom_delimiter")
row = layout.row(align=True) row = layout.row()
row.operator("bim.export_ifccsv", icon="EXPORT") split = row.split(factor=0.7)
row.operator("bim.import_ifccsv", icon="IMPORT") c = split.column()
c.operator("bim.export_ifccsv", icon="EXPORT")
c = split.column()
c.operator("bim.import_ifccsv", icon="IMPORT")