' 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