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 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 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
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?
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.
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.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
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide
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.