Create and export contact tool results for all time steps
Using ACT scripting, I would like to create a contact tool pressure result for all contacts with names ending by "YES". Then I would like to export the contact pressure results to a text file, for each time step.
Best Answer
-
The following script can be adapted to do this:
Define path to where results will be exported:
FilePath="C:\Users\pmaroneh\Downloads\" FileExtension=r".txt"
Reference some necessary items:
analysis = ExtAPI.DataModel.Project.Model.Analyses[0] # change number of analysis if necessary solution = analysis.Solution connections = ExtAPI.DataModel.Project.Model.Connections
In connections, find children that are contacts and create a list of these contact regions:
contactList = connections.GetChildren(DataModelObjectCategory.ContactRegion,True)
From this list, create another list for contacts which name end by "YES":
myContactList = [contact for contact in contactList if str(contact.Name).endswith("YES")]
For contacts in myContactList, create a contact tool / pressure result:
listContactIds=[contact.ObjectId for contact in contactList] # list of ids of items in contactList pressureList=[] for contact in myContactList: # loop on all contacts in myContactList newContactTool = solution.AddContactTool() # add a Contact Tool # remove all scoped contacts for id in listContactIds: newContactTool.InternalObject.RemoveScopedContact(id) # add scoping for contact newContactTool.InternalObject.AddScopedContact(contact.ObjectId) # add a pressure result pressure = newContactTool.AddPressure() # change result name pressure.Name="ContactPressure_" + contact.Name # store reference to result to reuse it later pressureList.append(pressure)
Loop on all time steps and export results:
resultData = analysis.GetResultsData() dataSets=resultData.ListTimeFreq # get result sets for resultSet in range(len(dataSets)): displayTime=dataSets[resultSet] # select display time unitTime='[sec]' # loop on pressure results for result in pressureList: # change display time result.DisplayTime=Quantity(str(displayTime) + unitTime) # evaluate result result.EvaluateAllResults() # export result result.ExportToTextFile(FilePath+result.Name+"_Time_"+str(displayTime)+FileExtension)
5
Answers
-
Hi Pernelle Marone-Hitz, Thanks for the script. But I have observed that the processing time increases with increase in number of contacts. This might be because of for loop that is used to remove all scoped contacts before assigning required contacts.
Can you please suggest some ways to reduce this processing time?
0