Example of resolving UIThread error message - take screenshot in Mechanical
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
Do we have an example of resolving a UIThread error message for Mechanical scripting?
Tagged:
2
Answers
-
Below is an example. If ExtAPI.Graphics.ExportImage() is called directly from OnButtonClickScreenshot function, the screenshot is not taken and the UIThread error message is returned. To resolve this, ExtAPI.Graphics.ExportImage() is called in another function, thanks to ExtAPI.Application.InvokeUIThread().
def OnButtonClickScreenshot(s, e): ''' Action when button is clicked (need to separate process in UIThread) ''' imagePath = GetUserFileFolder() imageName = "DummyImage" + str(imageNumber) ExtAPI.Application.InvokeUIThread(TakeScreenshot, [imagePath, imageName]) def TakeScreenshot(args): ''' Take screenshot of object ''' imagePath = args[0] imageName = args[1] setting2d = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() setting2d.Resolution = GraphicsResolutionType.HighResolution setting2d.Width = 838 setting2d.Height = 392 setting2d.Background = GraphicsBackgroundType.White setting2d.CurrentGraphicsDisplay = False totalPath = os.path.join(imagePath, imageName) + '.png' ExtAPI.Graphics.ExportImage(totalPath, GraphicsImageExportFormat.PNG, setting2d)
2