How to get and export SPL farfield results for different design points using scripting?

Erik Kostson
Member, Moderator, Employee Posts: 327
✭✭✭✭
Say we have some far field acoustic SPL results (e.g., far field microphones). How can we using scripting export these for every design point in an automatic way inside Workbench Mechanical?
Tagged:
0
Comments
-
Below is one way of doing this (using a Python Code After Post Object - exports the below marked results):
def after_post(this, solution):# Do not edit this line import csv import wbjn model = ExtAPI.DataModel.Project.Model analysis=model.Analyses[0] dpn=wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP") farfieldres=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.AcousticFarFieldResult) for res in farfieldres: res.Activate() resn=res.Name if resn.split('c')[0]=='Far-field SPL Mi': # comment away if we need all far field results myx=res.XCoordinate myfile='D:\mysplmic'+str(myx)+str(dpn)+'.txt' res.ExportToTextFile(myfile)
If we want to write all data to one text file then the below is a possible workaround (use as reference and change as needed):
def after_post(this, solution):# Do not edit this line import csv import wbjn model = ExtAPI.DataModel.Project.Model analysis=model.Analyses[0] dpn=wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP") farfieldres=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.AcousticFarFieldResult) i=0 # skip header destfile='D:\mysplmictot.txt' wf=open(destfile,'a') #open file in user directory change as needed for res in farfieldres: res.Activate() resn=res.Name if resn.split('c')[0]=='Far-field SPL Mi': # comment away if we need all far field results myx=res.XCoordinate myfile='D:\mysplmic'+str(myx)+str(dpn)+'.txt' destfile='D:\mysplmictot.txt' res.ExportToTextFile(myfile) rf= open(myfile, 'r') for line in rf: if i>0: fr=line.split('\t')[0] db=line.split('\t')[1] wf.write(str(dpn+resn) + "," + str(fr) + ","+ str(db) + "\n") i=i+1 rf.close() i=0 wf.close()
1
This discussion has been closed.