Export Solution Combination Results to Table
Karri Deepak
Member, Employee Posts: 3
✭✭✭
in Structures
How can I export solution combination results to an Excel sheet?
0
Answers
-
-
import os import csv #Define the directory to save the output file directory = 'D:/' #Initialize a combined result container combined_result = [] solCombObjs = DataModel.GetObjectsByType(DataModelObjectCategory.SolutionCombination) for obj in solCombObjs: for solution in obj.Children: if solution.Name != 'Solution Information': #Activate the solution to access its data solution.Activate() #Access the Tabular Data pane paneTabular = ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData) control = paneTabular.ControlUnknown #Retrieve row and column counts num_columns = control.ColumnsCount+1 num_rows = control.RowsCount+1 # Add a header or separator for clarity in the combined result combined_result.append([solution.Name]) #Loop through rows and columns to fetch data for row in range(1, num_rows): row_data = [] for col in range(1, num_columns): row_data.append(control.cell(row, col).Text) combined_result.append(row_data) #Add a blank line as a separator between solution results (optional) #Define the output file name output_file = os.path.join(directory, 'Solution_Combination_file.csv') #Write the combined results to the CSV file with open(output_file, 'wb') as f: writer = csv.writer(f) writer.writerows(combined_result)
1