How to take a ScreenShot of your Mechanical Application

Options
Vishnu
Vishnu Member, Employee Posts: 214
Name Dropper First Anniversary Solution Developer Community of Practice Member First Comment
edited December 2023 in Structures

You might need to create Screen Shot of the graph or Table sometimes. You can get the coordinates and use the below script.

Tagged:

Best Answers

  • Vishnu
    Vishnu Member, Employee Posts: 214
    Name Dropper First Anniversary Solution Developer Community of Practice Member First Comment
    Answer ✓
    Options

    The below Script Saves 2 PNG screen captures in your D:/ Drive

    import clr
    import os
    import sys
    clr.AddReference("System.Windows.Forms")
    clr.AddReference("System.Drawing")
    
    from System.Drawing import Bitmap,Graphics,Point,Size
    from System.Windows.Forms import(
        Application,Button,Form,FormWindowState,
        PictureBox,Screen)
    UserFiles="D:"
    Fname="sample.png"
    
    bmp=Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height)
    g=Graphics.FromImage(bmp)
    g.CopyFromScreen(0,0,0,0,bmp.Size)
    bmp.Save(os.path.join(UserFiles,Fname+".png"))
    g.Dispose()
    
    Fname="PartScreen.png"
    bmp=Bitmap(550,1000)
    g=Graphics.FromImage(bmp)
    g.CopyFromScreen(0,0,0,0,Size(550,50))
    bmp.Save(os.path.join(UserFiles,Fname+".png"))
    g.Dispose()
    

Answers

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

    Warning. All the methods exposed here use unsupported/undocumented commands. There is no guarantee that the script will work and/or that the APIs will not change in between versions. Use at your own risk.