Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
' 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 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:"
Dim outputDirectory As String = folderName
Dim strPartJpg As String = ""
Dim wpModelingView As ModelingView
Dim strCurrentDate as String
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
folderBrowserDialog1.ShowNewFolderButton = False
Dim result As DialogResult = folderBrowserDialog1.ShowDialog()
If (result = DialogResult.OK) Then
folderName = folderBrowserDialog1.SelectedPath
End If
If Not Directory.Exists(outputDirectory) Then
MsgBox("The specified directory does not exist, journal will now exit", MsgBoxStyle.Exclamation, outputDirectory & " not found")
Exit Sub
End If
strCurrentDate = format(Today, "dd.MM.y")
strPartJpg = Path.GetFileNameWithoutExtension(workPart.FullPath) & "_" & strCurrentDate & ".jpg"
strPartJpg = Path.Combine(outputDirectory, 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
[COLOR=green]' NX 7.5.5.4[/color]
[COLOR=green]'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=327914&tmac=fav&val=1,327914[/URL][/color]
[COLOR=blue]Option Strict Off[/color]
[COLOR=blue]Imports[/color] System
[COLOR=blue]Imports[/color] System.IO
[COLOR=blue]Imports[/color] System.Windows.Forms
[COLOR=blue]Imports[/color] NXOpen
[COLOR=blue]Imports[/color] NXOpen.UF
[COLOR=blue]Imports[/color] NXOpen.Assemblies
[COLOR=blue]Imports[/color] NXOpen.Utilities
[COLOR=blue]Imports[/color] NXOpen.Layer
[COLOR=blue]Module[/color] Module1
[COLOR=blue]Sub[/color] Main()
[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work
[COLOR=blue]Dim[/color] partName [COLOR=blue]As String =[/color] Path.GetFileNameWithoutExtension(workPart.FullPath)
[COLOR=green]'turn triad off[/color]
theSession.Preferences.ScreenVisualization.TriadVisibility [COLOR=blue]=[/color] 0
[COLOR=green]'directory to output jpegs, change as needed[/color]
[COLOR=green]'Change the directory to where you would like the picture for now[/color]
[COLOR=green]'the next update will feature automatic storing into Vantage folders for that job[/color]
[COLOR=blue]Dim[/color] folderName [COLOR=blue]As String =[/color] "C:"
[COLOR=green]'assign output folder to workpart folder[/color]
folderName [COLOR=blue]=[/color] Path.GetDirectoryName(workPart.FullPath)
[COLOR=green]'get parent folder (up a level)[/color]
[COLOR=blue]Dim[/color] directoryInfo [COLOR=blue]As[/color] DirectoryInfo
directoryInfo [COLOR=blue]=[/color] Directory.GetParent(folderName)
[COLOR=green]'assign the parent folder to folderName[/color]
folderName [COLOR=blue]=[/color] directoryInfo.FullName
[COLOR=blue]Dim[/color] strPartJpg [COLOR=blue]As String =[/color] ""
[COLOR=blue]Dim[/color] strCurrentDate [COLOR=blue]As String =[/color] Format(Today, "dd.MM.y")
[COLOR=blue]Dim[/color] s [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Dim[/color] ui [COLOR=blue]As[/color] UI [COLOR=blue]=[/color] UI.GetUI()
[COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] s.ListingWindow
[COLOR=blue]Dim[/color] root [COLOR=blue]As[/color] Component [COLOR=blue]=[/color] s.Parts.Work.ComponentAssembly.RootComponent
[COLOR=blue]Dim[/color] folderBrowserDialog1 [COLOR=blue]As New[/color] FolderBrowserDialog
[COLOR=blue]With[/color] folderBrowserDialog1
.Description [COLOR=blue]=[/color] "Specify folder for screenshot output"
.ShowNewFolderButton [COLOR=blue]= False[/color]
.RootFolder [COLOR=blue]=[/color] Environment.SpecialFolder.Desktop
[COLOR=green]'use folderName as default directory[/color]
.SelectedPath [COLOR=blue]=[/color] folderName
End [COLOR=blue]With[/color]
[COLOR=blue]Dim[/color] result [COLOR=blue]As[/color] DialogResult [COLOR=blue]=[/color] folderBrowserDialog1.ShowDialog()
[COLOR=blue]If[/color] (result [COLOR=blue]=[/color] DialogResult.OK) [COLOR=blue]Then[/color]
folderName [COLOR=blue]=[/color] folderBrowserDialog1.SelectedPath
[COLOR=blue]Else[/color]
[COLOR=green]'user pressed cancel, exit the journal[/color]
[COLOR=blue]Exit Sub[/color]
End [COLOR=blue]If[/color]
[COLOR=blue]If Not[/color] Directory.Exists(folderName) [COLOR=blue]Then[/color]
MsgBox("The specified directory does [COLOR=blue]not[/color] exist, journal will now exit", MsgBoxStyle.Exclamation, folderName [COLOR=blue]&[/color] " [COLOR=blue]not[/color] found")
[COLOR=blue]Exit Sub[/color]
End [COLOR=blue]If[/color]
strPartJpg [COLOR=blue]=[/color] Path.GetFileNameWithoutExtension(workPart.FullPath) [COLOR=blue]&[/color] "_" [COLOR=blue]&[/color] strCurrentDate [COLOR=blue]&[/color] ".jpg"
strPartJpg [COLOR=blue]=[/color] Path.Combine(folderName, strPartJpg)
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.Original)
[COLOR=green]'turn triad on[/color]
theSession.Preferences.ScreenVisualization.TriadVisibility [COLOR=blue]=[/color] 1
End [COLOR=blue]Sub[/color]
[COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As Integer[/color]
[COLOR=green]'Unloads the image when the NX session terminates[/color]
GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination
End [COLOR=blue]Function[/color]
End [COLOR=blue]Module[/color]
[COLOR=blue]Dim[/color] folderName [COLOR=blue]As String =[/color] "C:"
[COLOR=green]'assign output folder to workpart folder[/color]
folderName [COLOR=blue]=[/color] Path.GetDirectoryName(workPart.FullPath)
[COLOR=green]'get parent folder (up a level)[/color]
[COLOR=blue]Dim[/color] directoryInfo [COLOR=blue]As[/color] DirectoryInfo
directoryInfo [COLOR=blue]=[/color] Directory.GetParent(folderName)
[COLOR=green]'assign the parent folder to folderName[/color]
folderName [COLOR=blue]=[/color] directoryInfo.FullName
[highlight #FCE94F][COLOR=blue]If[/color] IO.Directory.Exists(IO.Path.Combine(directoryInfo.FullName, "Job_Pictures")) Then
folderName [COLOR=blue]=[/color] IO.Path.Combine(directoryInfo.FullName, "Job_Pictures")
End [COLOR=blue]If[/color][/highlight]