How to take a ScreenShot of your Mechanical Application

Vishnu
Vishnu Member, Employee Posts: 221
100 Comments 100 Likes Name Dropper First Anniversary
✭✭✭✭
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: 221
    100 Comments 100 Likes Name Dropper First Anniversary
    ✭✭✭✭
    Answer ✓

    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: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭

    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.