Compare Text in Note

Hi,

I want to compare the notes on Dwg for identify the repetitive things . Ended up with different methods, Please help me to figure this out...

Thanks,
Joe

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Windows.Forms
Imports NXOpen.Annotations
Imports NXOpen.Utilities
Imports System.Collections.Generic
Imports NXOpen.UF.UFDraw
Imports NXOpen.Drawings
Imports NXOpen.Drawings.DrawingCompareSettingsBuilder

' NX Font Update
' Journal created by Alto on 20-05-2015

Module NXJournal
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main()
Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("ideas_iso")

Dim NULL_TAG As NXOpen.Tag = NXOpen.Tag.Null
Dim obj As NXOpen.Tag = NULL_TAG

Do
obj = findnotes(obj)
If obj = NULL_TAG Then
GoTo end1
End If

Dim type As Integer = Nothing
Dim subtype As Integer = Nothing
ufs.Obj.AskTypeAndSubtype(obj, type, subtype)
Dim nxobj As NXObject = NXObjectManager.Get(obj)

If nxobj.GetType().ToString() = "NXOpen.Annotations.note" Then
Dim note2 As Annotations.Note = nxobj

Dim text2() As String
text2 = note2.GetText
For Each note1 As Note In workPart.Notes.ToArray
Dim text1() As String
text1 = note1.GetText()

If String.Compare(text1(0), text2(0)) = True Then

Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = note2.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = note2.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 0.1
generalText1.CharacterSpaceFactor = 1.0
generalText1.AspectRatio = 1.0
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 186
generalText1.Cfw.Font = fontIndex1
generalText1.Cfw.Width = Annotations.LineWidth.Thin
letteringPreferences1.SetGeneralText(generalText1)
note2.SetLetteringPreferences(letteringPreferences1)
note2.RedisplayObject()

End If
Next
End If

Loop Until obj = NULL_TAG
end1:

End Sub
Public Function findnotes(ByRef Obj As NXOpen.Tag)
Dim part As NXOpen.Tag = workPart.Tag
ufs.Obj.CycleObjsInPart(part, UFConstants.UF_note_type, Obj)
Return Obj
End Function

End Module

The following code should get you started. This journal loops through the note collection, comparing each note to those that come after it in the array. If a note with duplicate text is found, it is added to the "duplicateNotes" list.

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

Module Module1

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

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

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

Dim duplicateNotes As New List(Of Annotations.BaseNote)

Dim theNotes() As Annotations.BaseNote = workPart.Notes.ToArray

For i As Integer = 0 To theNotes.Length - 2

For j As Integer = i + 1 To theNotes.Length - 1

If SameNoteText(theNotes(i), theNotes(j)) Then
lw.WriteLine("duplicate found")
duplicateNotes.Add(theNotes(j))
End If

lw.WriteLine("")

Next
Next

For Each temp As Annotations.BaseNote In duplicateNotes
temp.Highlight()
Next

lw.WriteLine(duplicateNotes.Count.ToString & " duplicate notes found")

lw.Close()

End Sub

Function SameNoteText(ByVal note1 As Annotations.Note, ByVal note2 As Annotations.Note) As Boolean

Dim n1Lines() As String = note1.GetText
Dim n2Lines() As String = note2.GetText

Dim n1Text As String = String.Join(".", n1Lines)
Dim n2Text As String = String.Join(".", n2Lines)

lw.WriteLine("n1Text: " & n1Text)
lw.WriteLine("n2Text: " & n2Text)

Dim compareType As StringComparison = StringComparison.CurrentCultureIgnoreCase

Dim result As Integer
result = String.Compare(n1Text, n2Text)

If result = 0 Then
Return True
Else
Return False
End If

End Function

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