Showing results for 
Search instead for 
Did you mean: 

Create image with a journal




I need to create an image (.jpg, .jpeg, .png,...) with a journal.

The problem is that NX doesn't record the function export->jpeg in the journal mode...

Is there any possibility?

Other solutions are also welcome.


Thanks in advance,



Re: Create image with a journal

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 partName As String = Path.GetFileNameWithoutExtension(workPart.FullPath)  
	'turn triad off
    theSession.Preferences.ScreenVisualization.TriadVisibility = 0  
	'directory to output jpegs, change as needed
	'Change the directory to where you would like the picture for now
	'the next update will feature automatic storing into Vantage folders for that job
    Dim folderName As String = "C:"  
	'assign output folder to workpart folder
    folderName = Path.GetDirectoryName(workPart.FullPath)  
 'get parent folder (up a level)
        Dim directoryInfo As DirectoryInfo  
        directoryInfo = Directory.GetParent(folderName)  
 'assign the parent folder to folderName
        folderName = directoryInfo.FullName  

        Dim strPartJpg As String = ""  
        Dim strCurrentDate As String = Format(Today, "dd.MM.y")  
        Dim ui As UI = UI.GetUI()  
        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  
 '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  
        strPartJpg = Path.GetFileNameWithoutExtension(workPart.FullPath) & "_" & strCurrentDate & ".jpg"  
        strPartJpg = Path.Combine(folderName, strPartJpg)  
        ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.Original)  
 'turn triad on
        theSession.Preferences.ScreenVisualization.TriadVisibility = 1  
    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
Thank you...

Using NX 11 / RuleDesigner PDM

Re: Create image with a journal

Thanks so much!
But what do I have to change if i don't want to choose the directory? I want to have one standard path where it should be saved because I need to run the journal with run_journal.exe

Re: Create image with a journal


Ok I got it now.


But I have another problem: If i run the journal with the run_journal.exe there is an error which says UI is not defined.


This is the line: Dim ui As UI = UI.GetUI()


Does anybody have a solution for this?



Re: Create image with a journal

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The UI is only valid in interactive mode, in batch mode it is not valid.

Since the journal doesn't use the UI at all, remove the line to make things work.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 ( | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0

Employees of the customers, together we are strong Smiley Wink
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide

Re: Create image with a journal


If I remove the line I get an error



Re: Create image with a journal

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

I'm pretty sure that you cannot export screenshots if there is no visible UI.

Re: Create image with a journal

Siemens Phenom Siemens Phenom
Siemens Phenom

The posted jouornal uses UFSession.Disp, which requires an interactive session with a display.

Re: Create image with a journal

Siemens Phenom Siemens Phenom
Siemens Phenom


As Jim mentioned, that method is "internal only", so you cannot use it in an external program.  We do have two functions that you can use if you want to make .JPG files of your geometry in an external program - UF_DISP_batch_shade and UF_DISP_batch_shade_options.


When you are using wrapped call from the UF kit, it is always a good idea to see the Open C Reference for all the details about the call.  UF_DISP_create_image() is marked as "Internal", which is how we flag a method that can only be used in an interactive session.