Replace Text in a note

Hi all,

I have notes that have the following format scattered throughout a multi page drawing pack:

"1) note 1
2) note 2
3) Note 3"

In that note, I want to replace Note 2 with new note 2. I have written the following to do that, but I have been given the error "Line 39: Value of type "1-dim array of sting cannot be converted to 'system.collections.generic.list(ofstring)' Now I realise there is a type missmatch but I am now lost as to how to check through each item in that array for the text I want to replace. Can anyone help?

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "update notes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim NoteTBR As String = ""
Dim NewNote As String = ""
Dim BodyText As String = ""
Dim TextArray As New List(Of String)

'NoteTBR = InputBox("What text would you like to replace?")
'NewNote = InputBox("What text would you like to replace it with?")

Dim noteName As String = "M124-XX/M1"
Dim noteText As String = "M-124-XX/M1"

For Each tempNote As Annotations.Note In workPart.Notes
if (len(tempNote.GetText())>0) Then
lw.WriteLine(str(len(tempNote.GetText())))
lw.WriteLine(str(len(TextArray)))
TextArray = tempNote.GetText()
lw.WriteLine("This tempNote is " & tempNote.Name)
For Each temp As String In TextArray
lw.WriteLine("This Note contains " & temp)
If tempNote.Name = noteName Then

Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(tempNote)

draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim text1(0) As String
text1(0) = noteText
draftingNoteBuilder1.Text.TextBlock.SetText(text1)

Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()

draftingNoteBuilder1.Destroy()

End If
Next
End if
Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Try this:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "update notes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim NoteTBR As String = ""
Dim NewNote As String = ""
Dim BodyText As String = ""
'Dim TextArray As New List(Of String)

'NoteTBR = InputBox("What text would you like to replace?")
'NewNote = InputBox("What text would you like to replace it with?")

Dim noteName As String = "M124-XX/M1"
Dim noteText As String = "M-124-XX/M1"

For Each tempNote As Annotations.Note In workPart.Notes
if (tempNote.GetText().Length)>0 Then
lw.WriteLine(tempNote.GetText().Length.ToString)
'lw.WriteLine(str(len(TextArray)))
'TextArray = tempNote.GetText()
lw.WriteLine("This tempNote is " & tempNote.Name)
For Each temp As String In tempNote.GetText()
lw.WriteLine("This Note contains " & temp)
If tempNote.Name = noteName Then

Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(tempNote)

draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim text1(0) As String
text1(0) = noteText
draftingNoteBuilder1.Text.TextBlock.SetText(text1)

Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()

draftingNoteBuilder1.Destroy()

End If
Next
End if
Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Ok so I tried this, but the problem is the name for all the notes is blank. So it doesnt end up replacing the text. The text is found in For Each temp As String In tempNote.GetText(). I went through the output and saw it come up in that field. Can I replace that text in that?

By default, the name of a note object is blank; it will not have a name until you give assign one. If you would like to search for certain text and replace it, have a look at:
http://nxjournaling.com/content/searching-word-or-character-annotation-text

It provides links to other threads that have code to do this.