Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUISession As UI = UI.GetUI
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim outputFile As String = IO.Path.Combine(myDocs, workPart.Leaf & "_notes.txt")
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
'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)
For Each tempNote As Annotations.Note In workPart.Notes
Dim noteLines() As String
noteLines = tempNote.GetText
For Each noteLine As String In noteLines
myWriter.WriteLine(noteLine)
Next
'leave blank line between notes
myWriter.WriteLine("")
Next
End Using
'lw.WriteLine("notes for NX part file: " & workPart.Leaf & " have been exported to: " & outputFile)
Dim response As Integer
Dim messages(3) As String
messages(0) = "notes for NX part file: " & workPart.Leaf
messages(1) = "Have been exported to: " & outputFile
messages(2) = ""
messages(3) = "Open file now?"
response = theUISession.NXMessageBox.Show("Notes export complete", NXOpen.NXMessageBox.DialogType.Question, messages)
'1 = Yes
'2 = No
If response = 1 Then
System.Diagnostics.Process.Start(outputFile)
End If
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module