Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export all notes to a text file or to the spreadsheet in NX9 Drafting 1

Status
Not open for further replies.

PSI-CAD

Computer
Joined
Feb 13, 2009
Messages
997
Location
FR
Hi,

Application Drafting:
Is the an easy way to export all notes to a text file or to the spreadsheet in NX9 ?

I need this function to send the .txt or .xlsx for translation

TIA

Regards
Didier Psaltopoulos
 
Try the following journal:

Code:
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

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top