Take screenshot of model in Mechanical

Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 873
✭✭✭✭
Answers
-
The following function can be used:
- def TakeScreenshot(args):
- '''
- Take screenshot of active object and save it to imagePath.png
- Note: this function needs to be called in another thread through ExtAPI.Application.InvokeUIThread(TakeScreenshot, [imagePath])
- '''
- try:
- imagePath = args[0]
- 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) + '.png'
- ExtAPI.Graphics.ExportImage(totalPath, GraphicsImageExportFormat.PNG, setting2d)
- except:
- ExtAPI.Log.WriteMessage("Error : Could not take screenshot")
2 -
Below is a suggested solution to get images of various items. The script will plot to file any selected tree item.
- # Script:
- my_directory = ExtAPI.UserInterface.UIRenderer.ShowFolderOpenDialog()
- plotItems = ExtAPI.DataModel.Tree.ActiveObjects
- def slashRemover(n):
- """
- removes / from geometry names
- """
- if '\' in n:
- n = n.replace('\','_')
- return n
- for item in plotItems:
- item.Activate()
- saveName = item.Name
- saveName = slashRemover(saveName)
- saveCat = item.Parent.Name
- try:
- saveCat = item.Parent.Parent.Name
- except:
- pass
- saveNameCat = my_directory + '\' + saveCat + '_' + saveName + '.png'
- print(saveNameCat)
- ExtAPI.Graphics.ExportScreenToImage(saveNameCat)
2