Hi all,
please go through below code and help me if any changes required to make it work better.
' NX 10.0.1.4
' Journal created by gashaik on Mon Apr 25 11:02:33 2016 India Standard Time
' Load options browse directly from file
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim Load1 As NXOpen.Session.UndoMarkId
Dim Location1 As String
Location1 = (NXInputBox.GetInputString("Location:(Please Remove "" Character from location)"))
If Location1 = "" Then Exit Sub
Load1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")
theSession.SetUndoMarkName(Load1, "Assembly Load Options Dialog")
theSession.Parts.LoadOptions.Restore(Location1)
MessageBox.Show(Location1, "Load Location", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
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
re: browse load options
Are any errors reported when you run your code? Does it do what you intend for it to do?
re: browse load options
No errors reported,
but I want add a list box with pre loaded locations about 5,
so that i can directly click in list box to load required .def file,
and message box need to show loaded file.
-[]-
This will search a directory for *.def files
This will search a directory for *.def files and put them in a list of options on a dialog box. Once the user selects an option, the program will load the selected *.def file and then display a messagebox stating what def file was selected.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim Load1 As NXOpen.Session.UndoMarkId
Dim SearchPath as String = "C:\Temp"
Dim DefFileList As New List(Of String)
For Each DefFile As String In Directory.GetFiles(SearchPath, "*.def", IO.SearchOption.AllDirectories)
DefFileList.Add(DefFile)
Next
Dim DefFiles As String() = DefFileList.ToArray
If DefFiles.Length = 0 Then
MessageBox.Show("No *.def files found. Exiting now.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim default_item As Integer = 0
Dim SelectionResponse As Integer = Nothing
SelectionResponse = theUFSession.Ui.DisplayMenu("SELECT THE DESIRED LOAD OPTIONS", default_item, DefFiles, DefFiles.Length)
theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If SelectionResponse < 5 Then
Exit Sub
End If
Dim ArrayValue As Integer = SelectionResponse - 5
Load1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")
theSession.SetUndoMarkName(Load1, "Assembly Load Options Dialog")
theSession.Parts.LoadOptions.Restore(DefFiles(ArrayValue))
MessageBox.Show(DefFiles(ArrayValue) & "Loaded", "Load Location", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
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
RE: This will search a directory for *.def files
Thanks for the help,
Its working more than I expected,
But a small change,
Please make it to show *.def file name in list instead of location.
-[]-
Try this.
Try this.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim Load1 As NXOpen.Session.UndoMarkId
Dim SearchPath as String = "C:\Temp"
Dim DefFileList As New List(Of String)
Dim DefLocationList As New List(of String)
For Each DefFile As String In Directory.GetFiles(SearchPath, "*.def", IO.SearchOption.AllDirectories)
DefFileList.Add(DefFile.Substring(DefFile.LastIndexOf("\") + 1))
DefLocationList.Add(DefFile)
Next
Dim DefFiles As String() = DefFileList.ToArray
Dim DefLocations AS String() = DefLocationList.ToArray
If DefFiles.Length = 0 Then
MessageBox.Show("No *.def files found. Exiting now.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Dim default_item As Integer = 0
Dim SelectionResponse As Integer = Nothing
SelectionResponse = theUFSession.Ui.DisplayMenu("SELECT THE DESIRED LOAD OPTIONS", default_item, DefFiles, DefFiles.Length)
theUFSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If SelectionResponse < 5 Then
Exit Sub
End If
Dim ArrayValue As Integer = SelectionResponse - 5
Load1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")
theSession.SetUndoMarkName(Load1, "Assembly Load Options Dialog")
theSession.Parts.LoadOptions.Restore(DefLocations(ArrayValue))
MessageBox.Show(DefFiles(ArrayValue) & "Loaded", "Load Location", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
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
Re: Browse Load Options
Exactly as I wanted,
Thank you very much.
-[]-