99
1010import Grasshopper as gh
1111from Grasshopper .Kernel import GH_RuntimeMessageLevel as RML
12-
12+ from diffCheck . df_error_estimation import DFVizResults
1313import csv
1414import os
1515
@@ -18,29 +18,42 @@ class CsvExporter(component):
1818 def RunScript (self ,
1919 i_dump : bool ,
2020 i_export_dir : str ,
21- i_results ):
21+ i_file_name : str ,
22+ i_export_seperate_files : bool ,
23+ i_result : DFVizResults ):
2224 """
2325 The csv-exporter component exports a list of values to a .csv file
2426
2527 :param i_dump: A flag indicating whether to perform the export.
2628 :param i_export_dir: The directory where the CSV file will be saved.
29+ :param i_file_name: The name of the file
30+ :param i_export_seperate_files: whether to export a different file for each part
2731 :param i_values: A list of values to be exported.
32+
33+ :return o_success: A string notifying the user for the successful export
2834 """
2935 if i_dump :
3036 # Ensure the export directory exists
3137 os .makedirs (i_export_dir , exist_ok = True )
3238
33- # Define the CSV file path
34- file_path = os .path .join (i_export_dir , 'exported_values.csv' )
39+ if i_export_seperate_files :
40+ # Export each list of values to a separate file
41+ for idx , list_of_values in enumerate (i_result .distances ):
42+ file_name = f"{ i_file_name } _{ idx + 1 } .csv"
43+ file_path = os .path .join (i_export_dir , file_name )
44+ with open (file_path , mode = 'w' , newline = '' ) as file :
45+ writer = csv .writer (file )
46+ writer .writerow ([list_of_values ])
47+ else :
48+ # Export all values to a single file
49+ file_path = os .path .join (i_export_dir , f"{ i_file_name } .csv" )
50+ with open (file_path , mode = 'w' , newline = '' ) as file :
51+ writer = csv .writer (file )
52+ for list_of_values in i_result .distances :
53+ writer .writerow ([list_of_values ])
3554
36- # Write the values to the CSV file
37- with open (file_path , mode = 'w' , newline = '' ) as file :
38- writer = csv .writer (file )
39- for list_of_values in i_results .distances :
40- writer .writerow ([list_of_values ])
41-
4255 o_success = "Successfully exported the values"
43-
56+
4457 return o_success
4558
4659
@@ -49,5 +62,7 @@ def RunScript(self,
4962# o_cvs = com.RunScript(
5063# i_dump,
5164# i_export_dir,
65+ # i_file_name,
66+ # i_export_seperate_files,
5267# i_results
5368# )
0 commit comments