Option Strict Off
Imports System
Imports NXOpen
Module save_selection
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObject As NXObject
lw.Open()
Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim outputFile As String = IO.Path.Combine(myDocs, "selection.log")
If IO.File.Exists(outputFile) Then
Try
IO.File.Delete(outputFile)
Catch ex As Exception
lw.WriteLine("error deleting file: " & outputFile)
Return
End Try
End If
Do Until SelectAnObject("Select object", _
mySelectedObject) = Selection.Response.Cancel
lw.WriteLine("Object journal identifier: " & mySelectedObject.JournalIdentifier)
lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
lw.WriteLine("")
'pass False to overwrite existing file, True to append existing file
'if file does not exist, a new file will be created and the True/False value will be ignored
Using myWriter As New IO.StreamWriter(outputFile, True)
myWriter.WriteLine(mySelectedObject.GetType.ToString)
myWriter.WriteLine(mySelectedObject.JournalIdentifier)
End Using
Loop
lw.Close()
End Sub
Function SelectAnObject(prompt As String, _
ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selObj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module