Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal for printscreen with white background 6

Status
Not open for further replies.

zhengrong

Mechanical
Aug 4, 2015
20
Does anybody know how to record the print screen key stroke in journal to get a screenshot of current graphic window with white background. And then the screenshot picture can be pasted in other file or email. Thank you
 
Replies continue below

Recommended for you

The following code will create a screenshot of your current display. It will create a file at the location you specify.

It does not put the image on your clipboard, but that should also be possible.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        'change export location as needed
        ExportScreenshot("C:\Temp\NX_screenshot.png")

        lw.Close()

    End Sub

    Sub ExportScreenshot(ByVal filename As String)

        Dim wcsVisible As Boolean = theSession.Parts.Display.WCS.Visibility
        Dim triadVisible As Integer = theSession.Preferences.ScreenVisualization.TriadVisibility


        Try
            DeleteFile(filename)

            theSession.Parts.Display.WCS.Visibility = False
            theSession.Preferences.ScreenVisualization.TriadVisibility = 0

            theUfSession.Disp.CreateImage(filename, UFDisp.ImageFormat.Png, UFDisp.BackgroundColor.White)
        Catch ex As Exception
            MsgBox(ex.Message & ControlChars.NewLine & _
                   "'" & filename & "' could not be created")
            'Return

        Finally
            theSession.Parts.Display.WCS.Visibility = wcsVisible
            theSession.Preferences.ScreenVisualization.TriadVisibility = triadVisible

        End Try

    End Sub

    Sub DeleteFile(ByVal filePath As String)

        'does file exist? if so, try to delete it (overwrite)
        If IO.File.Exists(filePath) Then
            IO.File.Delete(filePath)
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Here's the version to add the image to the clipboard.

Code:
Option Strict Off
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        'change export location as needed
        ExportScreenshot("C:\Temp\NX_screenshot.png")



        lw.Close()

    End Sub

    Sub ExportScreenshot(ByVal filename As String)

        Dim wcsVisible As Boolean = theSession.Parts.Display.WCS.Visibility
        Dim triadVisible As Integer = theSession.Preferences.ScreenVisualization.TriadVisibility


        Try
            DeleteFile(filename)

            theSession.Parts.Display.WCS.Visibility = False
            theSession.Preferences.ScreenVisualization.TriadVisibility = 0

            theUfSession.Disp.CreateImage(filename, UFDisp.ImageFormat.Png, UFDisp.BackgroundColor.White)
        Catch ex As Exception
            MsgBox(ex.Message & ControlChars.NewLine & _
                   "'" & filename & "' could not be created")
            'Return

        Finally
            theSession.Parts.Display.WCS.Visibility = wcsVisible
            theSession.Preferences.ScreenVisualization.TriadVisibility = triadVisible

        End Try

        'copy image to clipboard
        Dim theImage As Bitmap = CType(Image.FromFile(filename), Bitmap)
        Clipboard.SetImage(theImage)

    End Sub

    Sub DeleteFile(ByVal filePath As String)

        'does file exist? if so, try to delete it (overwrite)
        If IO.File.Exists(filePath) Then
            IO.File.Delete(filePath)
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Hi Cowski,
Thank you so much for your response. I think putting the image to the clipboard is exactly what I want. Since I might need to take more than one screenshot in one job and I even don't need to save them. I just need to screenshot it and then ctrl + V to paste it to email. This would be better for me than saving the picture, finding it, and attached it to email. Since when I click the printscreen key I always forget to change the background to white, I am trying to find a solution to incorporate changing background color into the printscreen hotkey. In this case, The screenshot will be white automatically once I click the printscreen or other hotkey.
Is there any code for putting the screen shot image to clipboard?
Thanks.
 
Hi Cowski,
I have tried this code and they are working perfectly. Thank you so much for the help
 
Apart from the white background , there is an existing function to copy the display to the clipboard.
"Copy Display".
Menu- Edit- Copy Display.
It's smart in the fashion that IF the display is STATIC wireframe mode, it will copy vectors, IF the display is Shaded mode, it will copy a bitmap.
The Vectors are scale-able without loss. ( and can be converted to, at least, powerpoint objects.)

Regards,
Tomas
 
I use a macro to change background to White then use the Windows Snipping tool to grab the graphics window or a portion of it.
 
Nice work Cowski!, that ones going on my toolbar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor