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.

how to extract the sheet number in which the note exist?

I wanted to limit the search to a single sheet. So if I had multiple drawings with similar tables, I could say only look at tables found on sheet 1 and it would limit the search to sheet 1. Does that make sense?

I wanted to limit the search to a single sheet. So if I had multiple drawings with similar tables, I could say only look at tables found on sheet 1 and it would limit the search to sheet 1. Does that make sense?

Something that I have not tested, but I think will work is to use the .AskVisibleObjects method on the drawing view. From here, you would need to sort through the returned objects to find the "tables" of interest.

Alternatively, you could iterate through all the tables and test to see which sheet it resides on with the code found here:
http://nxjournaling.com/comment/1095#comment-1095

If you need to reference the tables and sheets multiple times in your code, you could set up a dictionary object to store the sheet/table info. Your code would need to use one of the other methods mentioned to query the tables/sheets and set up the dictionary, but queries after that would be fairly easy and quick.

In my case, drawing have multiple sheet.I am trying to get the sheets that a note resides on. What to change in the above journal to serve my purpose?

TBH I was never able to find out which sheet the notes reside in. They are stored per drawing file, and it doesn't have a sheet property as far as I can find. If anyone finds a way please let me know as it would help with my project as well.

There is a round-about way to determine which sheet an object resides on, the subroutine to do that can be found here:
http://nxjournaling.com/comment/1095#comment-1095

It is taken from GTAC example nx_api4936 (also nx_api4937).