Take screenshot of model in Mechanical

Member, Moderator, Employee Posts: 873
100 Answers 500 Comments 250 Likes Second Anniversary
✭✭✭✭
edited June 2023 in Structures

How can I take a screenshot of the model in Mechanical?

Tagged:

Answers

  • Member, Moderator, Employee Posts: 873
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    The following function can be used:

    1. def TakeScreenshot(args):
    2. '''
    3. Take screenshot of active object and save it to imagePath.png
    4. Note: this function needs to be called in another thread through ExtAPI.Application.InvokeUIThread(TakeScreenshot, [imagePath])
    5. '''
    6. try:
    7. imagePath = args[0]
    8. setting2d = Ansys.Mechanical.Graphics.GraphicsImageExportSettings()
    9. setting2d.Resolution = GraphicsResolutionType.HighResolution
    10. setting2d.Width = 838
    11. setting2d.Height = 392
    12. setting2d.Background = GraphicsBackgroundType.White
    13. setting2d.CurrentGraphicsDisplay = False
    14. totalPath = os.path.join(imagePath) + '.png'
    15. ExtAPI.Graphics.ExportImage(totalPath, GraphicsImageExportFormat.PNG, setting2d)
    16. except:
    17. ExtAPI.Log.WriteMessage("Error : Could not take screenshot")
  • Member, Employee Posts: 252
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    edited November 2022 Answer ✓

    Below is a suggested solution to get images of various items. The script will plot to file any selected tree item.

    1. # Script:
    2. my_directory = ExtAPI.UserInterface.UIRenderer.ShowFolderOpenDialog()
    3.  
    4. plotItems = ExtAPI.DataModel.Tree.ActiveObjects
    5.  
    6. def slashRemover(n):
    7. """
    8. removes / from geometry names
    9. """
    10. if '\' in n:
    11. n = n.replace('\','_')
    12. return n
    13. for item in plotItems:
    14. item.Activate()
    15. saveName = item.Name
    16. saveName = slashRemover(saveName)
    17. saveCat = item.Parent.Name
    18. try:
    19. saveCat = item.Parent.Parent.Name
    20. except:
    21. pass
    22. saveNameCat = my_directory + '\' + saveCat + '_' + saveName + '.png'
    23. print(saveNameCat)
    24. ExtAPI.Graphics.ExportScreenToImage(saveNameCat)

Welcome!

It looks like you're new here. Sign in or register to get started.