Drawing sheet annotation search

Hello All,

I have found a way to isolate a single drawing sheet:

    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim dp As Part = s.Parts.Display
        Dim dsc As DrawingSheetCollection = dp.DrawingSheets
        Dim dsca As Array = dsc.ToArray()
        Dim ds As DrawingSheet = dsca(0)
    End Sub

I have been trying to find a way to search through the notes on this sheet, but I cant find a method or a property to call which shows the annotation. I want to search through them for a specific string of text. For Example "10 K". I have found a way to search the whole drawing for it, but I dont want to search the whole drawing as it seems inefficient and for larger drawing packs (10+sheets) the process will be slower. Does anyone know of a way to search through a specific drawing sheet for notes/annotations?

I think this would work, but there are probably more efficient ways to do this.

Dim ufs As UFSession = UFSession.GetUFSession()
Dim status As Integer = Nothing
Dim isOn As String = Nothing
Dim nc As NoteCollection = dp.Notes
        For Each anote As Note In nc
            ufs.View.AskViewDependentStatus(aNote.Tag, status, isOn)
            If status = 1 And isOn.Contains(ds.Name) Then
                'cycle through text lines in note for desired string
            End If
        Next

Hey,

Ive done it the dirty way as well.

 
 
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Imports NXOpen.Annotations
 
Module ChangeNoteWord
    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim dp As Part = s.Parts.Display
        Dim nc As NoteCollection = dp.Notes
        Dim lw As ListingWindow = s.ListingWindow
        lw.Open()
        Dim noteText() As String
        Dim numLines As Integer = 0
        For Each a_note As Note In nc
            noteText = a_note.GetText()
            numLines = noteText.Length
            For i As Integer = 0 To numLines-1
                If noteText(i).Contains("510k") OR noteText(i).Contains("510 k")Then
                    lw.WriteLine("We found a 510 k")
                End If
            Next
        Next       
 
    End Sub
 
End Module

So I have something like that already, I just want to limit it and keep it cleaner. I would rather just search the one page I know it's on rather than cycle every note in the file.

Could try something like this

Dim onSheet() As DisplayableObject = ds.View.AskVisibleObjects()
        For Each thisObject As DisplayableObject In onSheet
            'use thisObject.tostring() to filter for notes?
        Next

As you know, each part contains a note collection, but it is not broken down per drawing sheet. This leaves us with 2 basic strategies to find notes on a given sheet:

  • cycle through all the notes and query which sheet the note resides on
  • get all the visible objects on the desired sheet and sort out the note objects

The code posted by iamfallen* illustrates the first strategy, the code below shows the 2nd. It looks as the current drawing sheet, but you should be able to use any sheet that you like.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
 
    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow
 
    Sub Main()
 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
 
        lw.Open()
 
        Dim notesOnSheet As New List(Of Annotations.Note)
 
        lw.WriteLine("working with drawing sheet: " & theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet.Name)
 
        For Each temp As DisplayableObject In theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet.View.AskVisibleObjects
            If TypeOf (temp) Is Annotations.Note Then
                Dim theNote As Annotations.Note = temp
                For i As Integer = 0 To theNote.GetText.Length - 1
                    If theNote.GetText(i).Contains("test1") Then
                        lw.WriteLine("We found a 'test1'")
                    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

*Edit: it looks like iamfallen posted a second example while I was typing, his posts now show both methods.