×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journal for printscreen with white background
6

Journal for printscreen with white background

Journal for printscreen with white background

(OP)
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

RE: Journal for printscreen with white background

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

RE: Journal for printscreen with white background

2
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

RE: Journal for printscreen with white background

(OP)
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.

RE: Journal for printscreen with white background

Quote (zhengrong)

Is there any code for putting the screen shot image to clipboard?

Yes. See my 2nd post (above).

www.nxjournaling.com

RE: Journal for printscreen with white background

(OP)
Hi Cowski,
I have tried this code and they are working perfectly. Thank you so much for the help

RE: Journal for printscreen with white background

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

RE: Journal for printscreen with white background

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.

RE: Journal for printscreen with white background

Nice work Cowski!, that ones going on my toolbar

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources