I want to export the below information as a csv file directly from Mechanical via scripting. 1. Convection load Name 2. Film Coefficient 3. Film Coefficient unit 4. Ambient Temperature 5. Ambient Temperature unit
You can paste the below script in Mechanical scripting console to export all the convection loads corresponding to a thermal analysis (assumption --> this analysis is first in the tree. Please edit the index in DataModel.AnalysisList[i] to access other analyses)
import os #Provide the name of the CSV file fileName = 'Convection_Data.csv' #Select Analysis by Id analysis = DataModel.AnalysisList[0] #Function to write a CSV file from the gathered data def writeCSV(t1,fileName): ExtAPI.Log.WriteMessage('my File name ' + fileName) with open(fileName , 'w') as f: for line in t1: for col in line: #For Non-German f.write(str(col) + ', ') #For German OS #f.write(str(col).replace('.',',') + '; ') f.write('\n') #Find the user files directory for saving the data UserDir = r"D:\Cases\26832" saveName = os.path.join(UserDir,fileName) first_solution = analysis.Solution solver_data = first_solution.SolverData allConvections = DataModel.GetObjectsByType(DataModelObjectCategory.Convection) allData = [] for convectionObj in allConvections: convName = convectionObj.Name lastIndexConv = convectionObj.FilmCoefficient.Output.DiscreteValueCount-1 lastIndexAT = convectionObj.AmbientTemperature.Output.DiscreteValueCount-1 convFCVal = convectionObj.FilmCoefficient.Output.GetDiscreteValue(lastIndexConv).Value convFCUnit = convectionObj.FilmCoefficient.Output.GetDiscreteValue(lastIndexConv).Unit convATVal = convectionObj.AmbientTemperature.Output.GetDiscreteValue(lastIndexAT).Value convATUnit = convectionObj.AmbientTemperature.Output.GetDiscreteValue(lastIndexAT).Unit allData.append([convName, convFCVal, convFCUnit, convATVal, convATUnit]) writeCSV(allData,saveName)