Take screenshot of model in Mechanical

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

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

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    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")
    
  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited November 2022 Answer ✓
    Options

    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)