Workbook ACT reader reade result and GUI no response
I have develop a self ACT extension to extract all the steps results and this process take a lots of time. This process use ACT reader API and the workbench GUI is no response, is there any way to solve this problem and not to block the GUI thread ?
Comments
-
It depends a lot on what you mean by “extract”. You can use the threading module in this operation, but Mechanical is not a multi thread safe application, so anything you do with the sync thread should not try to interact with Mechanical at all. For example, writing to a file on the hard drive is not interacting with Mechanical, but trying to create a contour plot is.
The other thing to try is using DPF for better performance across time steps in results extraction.
0 -
@Mike.Thompson said:
It depends a lot on what you mean by “extract”. You can use the threading module in this operation, but Mechanical is not a multi thread safe application, so anything you do with the sync thread should not try to interact with Mechanical at all. For example, writing to a file on the hard drive is not interacting with Mechanical, but trying to create a contour plot is.The other thing to try is using DPF for better performance across time steps in results extraction.
The main event function as follow, reader.GetResult('BOLT') to extract bolt pretension force and reader.GetResult('BFE') to extract the bolt temperature and calculating some result to write to Excel file.
There are about 160 steps in my results file, so extract all the steps results take a long time. I am not sure crete a new thread in Mechanical is OK or not ?def Assessment(self, sender, args): def BoltDatasCheck(BoltAssessTypes, BoltLoadDiameters, BoltLoadPitches): # function to check datas def GetBodySurfaceMidElements(modelMesh, FacesAxials, BoltCenter, BoltBodyElementIds, ModelMeshLengthConvert): # function to get elmentIds def GetBoltPreNodesIds(analysis, reader, StepsTimes, BoltLoads, BoltCenter): # function to get BoltPreNodesIds def GetBodyElementsNodesCount(reader, StepsTimes, BFEResults, BoltBodyElementIds): # function to get NodesCount def GetMaxBoltResult(reader, time, BoltLoads, BFEResults, BoltPreNodesIds, BoltBodyElementIds, BodyElementsCount, BoltForceConve, BFEUnitConvert): reader.CurrentTimeFreq = time BoltForce = {} BoltForce[time] =[force*BoltForceConve for force in BoltLoads.GetNodeValues(BoltPreNodesIds)] AllBFEelementIds = [] for ElemntIds in BoltBodyElementIds: AllBFEelementIds.extend(ElemntIds) AllElementsBFE = BFEResults.GetElementValues(AllBFEelementIds, False) BoltBFE = {} BoltBFE[time] = [0.0] * len(BoltBodyElementIds) for index, count in enumerate(BodyElementsCount): if index == 0: BoltBFE[time][index] = max(AllElementsBFE[:count]) * BFEUnitConvert else: startcount = BodyElementsCount[index - 1] BoltBFE[time][index] = max(AllElementsBFE[startcount:count]) * BFEUnitConvert return (BoltForce, BoltBFE) # .........Some function code reader = self.analysis.GetResultsData() # StepsNum = reader.ResultSetCount StepsTimes = list(reader.ListTimeFreq) StepsTimes = StepsTimes[1:] BoltLoads = reader.GetResult('BOLT') BoltLoads.SelectComponents(['LOAD']) BoltForceConve = units.ConvertUnit(1.0, BoltLoads.GetComponentInfo('LOAD').Unit, 'N', 'Force') BFEResults = reader.GetResult('BFE') BFEResults.SelectComponents(['BFE']) BFEUnitConvert = units.ConvertUnit(1.0, BFEResults.GetComponentInfo('BFE').Unit, 'C') BoltPreNodesIds = GetBoltPreNodesIds(self.analysis, reader, StepsTimes, BoltLoads, BoltCenter) BodyElementsCount = GetBodyElementsNodesCount(reader, StepsTimes, BFEResults, BoltBodyElementIds) BoltForces = {} BoltTemperatures = {} for time in StepsTimes: Result = GetMaxBoltResult(reader, time, BoltLoads, BFEResults, BoltPreNodesIds, BoltBodyElementIds, BodyElementsCount, BoltForceConve, BFEUnitConvert) BoltForces.update(Result[0]) BoltTemperatures.update(Result[1]) # Other function code
By the way, the normal create a thread as following in Mechanical ?
import threading thread = threading.Thread(target=func, args=()) thread.start()
0 -
@Mike.Thompson
I have create a thread in Button event function and using ExtAPI.Application.InvokeUIThread method to get reader, MeshData, etc object.def internalGetAnalysisData(args): args[1] = args[0].Name args[2] = args[0].WorkingDir args[3] = args[0].GetResultsData() args[4] = args[0].GeoData args[5] = args[0].MeshData def Assessment(self, sender, args): def AssessThread(): # other code args = [self.analysis, None, None, None, None, None] ExtAPI.Application.InvokeUIThread(internalGetAnalysisData, args) modelMesh = args[5] reader = args[3] # other code thread = threading.Thread(target=AssessThread, args=()) thread.start()
But there still some Errors for some command.
Is there any way to find which command (or line number) should use ExtAPI.Application.InvokeUIThread method ?This command cannot be directly invoked from this callback. (This callback uses a different thread than the UIThread.) Please use the method 'InvokeUIThread' from ExtAPI.Application instead.
0 -
delete
0 -
delete
0