Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal Jpg Exports / Graphics Window Question

Status
Not open for further replies.

cquinker

Bioengineer
Sep 20, 2012
16
Over the last few days I've been looking into how to export framed images of the graphics windows to jpeg files through NX journaling in NX 7.5. The 'CreateFramedImage' method allows for the export of a rectangular window of the graphics window. Additionally, the function allows for you to specify this rectangular box in pixels. Unfortunately, I can see no way of identifying the pixel size (width x height) of the NX graphics window from within the journal or in the NX menus either. My ultimate goal is to export an image of the entire model (solid bodies) that is as small as possible while still containing all of the model within the image. Any help at all will be appreciated.
 
Replies continue below

Recommended for you

Try this, I had some help creating it and it will export the current NX screen as a JPEG saved as the workpart name to a folder of your choice. I had some major helping getting it to run like this!

Code:
' NX 7.5.5.4
'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=327914&tmac=fav&val=1,327914[/URL]

Option Strict Off  
Imports System  
Imports System.IO  
Imports System.Windows.Forms  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Assemblies  
Imports NXOpen.Utilities  
Imports NXOpen.Layer  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim ufs As UFSession = UFSession.GetUFSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim background_color As UFDisp.BackgroundColor = UFDisp.BackgroundColor.original
        Dim DisplayPart As Part = theSession.Parts.display
        Dim partName As String = Path.GetFileNameWithoutExtension(workPart.FullPath)  
 'turn triad off
        theSession.Preferences.ScreenVisualization.TriadVisibility = 0
'turn WCS off
         DisplayPart.WCS.Visibility = False   
        
        Dim folderName As String = "C:"  
        Dim strPartJpg As String = ""  
        Dim strCurrentDate As String = Format(Today, "dd.MM.y")  
        Dim s As Session = Session.GetSession()  
        Dim ui As UI = UI.GetUI()  
        Dim lw As ListingWindow = s.ListingWindow  
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent  
        Dim folderBrowserDialog1 As New FolderBrowserDialog  
        With folderBrowserDialog1  
            .Description = "Specify folder for screenshot output"  
           .ShowNewFolderButton = False  
            .RootFolder = Environment.SpecialFolder.Desktop  
 'use folderName as default directory
            .SelectedPath = folderName   
        End With  
        Dim result As DialogResult = folderBrowserDialog1.ShowDialog()  

        If (result = DialogResult.OK) Then  
            folderName = folderBrowserDialog1.SelectedPath  
        Else  
 'user pressed cancel, exit the journal
            Exit Sub  
        End If  

        If Not Directory.Exists(folderName) Then  
            MsgBox("The specified directory does not exist, journal will now exit", MsgBoxStyle.Exclamation, folderName & " not found")  
            Exit Sub  
        End If  
            Dim partLoadStatus2 As PartLoadStatus
            Dim status1 As PartCollection.SdpsStatus
            status1 = theSession.Parts.SetDisplay(displaypart, False, True, partLoadStatus2)
            'workPart = theSession.Parts.Work
            'displayPart = theSession.Parts.Display
            partLoadStatus2.Dispose()

        strPartJpg = Path.GetFileNameWithoutExtension(workPart.FullPath) & "_" & strCurrentDate & ".jpg"  
        strPartJpg = Path.Combine(folderName, strPartJpg)  
        ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, background_color)  
 'turn triad on
        theSession.Preferences.ScreenVisualization.TriadVisibility = 1
'turn WCS off
         DisplayPart.WCS.Visibility = true
    End Sub  
    Public Function GetUnloadOption(ByVal dummy As String) As Integer  
 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  
    End Function  
End Module
 
dhusk09,

I appreciate your quick feedback. However, I am able to export the entire graphics window without any issues. My main issue still remains to be specifying a rectangular box within the graphics window that will be exported. Additionally, I still have no way of identifying the window size in pixels from within the journal.
 
Okay, so I found a jerry-rigged way of finding the graphics window's pixel size:

Option Strict Off
Imports System
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Assemblies
Imports System.Xml

Module NXJournal

Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim pixel_x As Integer
Dim pixel_y As Integer
theSession.Preferences.HighQualityImageVisualization.GetImageSize(size_dummy, pixel_x, pixel_y)

End Sub

Where pixel_x and pixel_y contain the number of pixels of the graphics window. However, an issue arises when the nx window is resized without executing an action that redetermines the graphics window size. This can easily be achieved by the following lines (renders the current viewing window):

workPart.ModelingViews.WorkView.HiqhQualityImage.Generate()
workPart.ModelingViews.WorkView.HiqhQualityImage.Erase()

 
You should check out thread561-331483. Near the end of the thread, kukelyk has posted some code that exports a jpg and automatically crops it to size.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor