Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
(OP)
thread561-352708: NXOpen - Find note that resides in a drawing sheet
Hi The below Journal doest work for label notes, NX 8.5... can somebody help me here
[i]
Hi The below Journal doest work for label notes, NX 8.5... can somebody help me here
[i]
CODE --> English
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Imports NXOpen.Annotations
Module GetWordInfo
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Sub Main()
Dim dp As Part = s.Parts.Display
Dim nc As NoteCollection = dp.Notes
Dim textin As String = "text to find"
Try
textin = NXInputBox.GetInputString("Get Note Info", "Text to Find", textin)
Catch ex As Exception
GoTo end1
End Try
Dim dwgs As Drawings.DrawingSheetCollection
dwgs = dp.DrawingSheets
Dim notestring() As String
lw.Open()
For Each sheet As Drawings.DrawingSheet In dwgs
sheet.Open()
For Each a_note As Note In nc
notestring = a_note.GetText()
If notestring(0) = textin Then
lw.WriteLine(sheet.Name & " , " & notestring(0))
End If
Next
Next
end1:
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 




RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
The above code is from a closed thread, Which is used search for a particular text in Drawing notes and replace..
Whereas my requirement is different, but with little modification to above code will work (i feel)
I want to search for all Annotation.labels (which contains particular text anywhere in it) in drawing sheet and list the text string in Information window.
Can somebody help me out here
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Anyways, the code below should work.
CODE --> VB
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpenUI Imports NXOpen.Utilities Imports NXOpen.Annotations Module GetWordInfo Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim dp As Part = s.Parts.Display Dim lc As LabelCollection = dp.Labels Dim textin As String = "text to find" Try textin = NXInputBox.GetInputString("Get Label Info", "Text to Find", textin) Catch ex As Exception GoTo end1 End Try Dim dwgs As Drawings.DrawingSheetCollection dwgs = dp.DrawingSheets Dim labelstring() As String lw.Open() For Each sheet As Drawings.DrawingSheet In dwgs sheet.Open() For Each a_label As Label In lc labelstring = a_label.GetText() If labelstring(0).Contains(textin) Then lw.WriteLine(labelstring(0)) End If Next Next end1: 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 ModuleGraham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
The code only searches for labelstrings in the first line of the text, If the "text to find" is in second or other lines, its not working..
If suppose i change the code to
CODE --> english
But, i want to search for the "text to find" in the entire label note and list in information window....
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpenUI Imports NXOpen.Utilities Imports NXOpen.Annotations Module GetWordInfo Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim dp As Part = s.Parts.Display Dim lc As LabelCollection = dp.Labels Dim textin As String = "text to find" Dim textfound As Boolean = False Try textin = NXInputBox.GetInputString("Get Label Info", "Text to Find", textin) Catch ex As Exception GoTo end1 End Try Dim dwgs As Drawings.DrawingSheetCollection dwgs = dp.DrawingSheets Dim labelstring() As String lw.Open() For Each sheet As Drawings.DrawingSheet In dwgs sheet.Open() For Each a_label As Label In lc labelstring = a_label.GetText() For i As Integer = 0 To labelstring.Length - 1 If labelstring(i).Contains(textin) Then textfound = True End If Next If textfound = True Then For i As Integer = 0 To labelstring.Length - 1 lw.WriteLine(labelstring(i)) Next lw.WriteLine(vbCrLf) End If textfound = False Next Next end1: 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 ModuleFrank Swinkels
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
The following modified loop should work OK:
CODE --> VB.NET
For Each sheet As Drawings.DrawingSheet In dwgs sheet.Open() For Each a_label As Label In lc labelstring = a_label.GetText() For Each labelstringitem As String In labelstring If labelstringitem.Contains(textin) Then lw.WriteLine(labelstringitem) End If Next Next NextGraham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Graham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Thanks Frank & Grinch for the codes...
I have made changes to my code and now it works fine.. but some improvement is needed
Meanwhile i found out, that looping through sheets is giving repeated data, because the text string is searched in label.collection instead of the displayed sheets. I understand label.collection holds all the label string in a drawing, irrespective of displayed sheet. So, looping through sheets is not required.
Also, I want to search for two different words in label.collection and all permutation of two words should yield results, and i don't want user interaction there.. I have included the "text to find" in code itself. (this part is completed and working fine)
According to the above, i have modified the code...
Now, i want to have few improvements.
1. Sheet.name for the found text string is needed, Example (Sheet1 Text srting1 ; Text string2 ; ......etc)
2. I want to have a separator between the text strings " ; " (line1 textstring ; line2 text string ; and so on till it ends..) because i have to import the list window data to excel...
Help me out here
CODE --> english
' NX 8.0.3.4 Option Strict Off Imports System Imports NXOpen Module NXJournal Dim s As Session = Session.GetSession() Dim dp As Part = s.Parts.Display Dim lw As ListingWindow = s.ListingWindow Sub Main Dim dp As Part = s.Parts.Display Dim lbs As NXOpen.Annotations.LabelCollection = dp.Labels Dim textin As String = "XXX" : Dim textin2 As String = "YYY" Dim dwgs As Drawings.DrawingSheetCollection dwgs = dp.DrawingSheets Dim Labelstring() As String If Not lw.IsOpen Then lw.Open() For Each a_Label As NXOpen.Annotations.Label In lbs Labelstring = a_Label.GetText() Dim TempStr As String = String.Empty Dim IsValid As Boolean = False For ii As Integer = 0 To Labelstring.Length- 1 If Labelstring(ii).Contains(textin) Or Labelstring(ii).Contains(textin2) Then IsValid = True End If Next If IsValid Then For ii As Integer = 0 To Labelstring.Length- 1 If Not String.IsNullOrEmpty(TempStr) Then TempStr = TempStr & " " & Labelstring(ii) Else TempStr = Labelstring(ii) End If Next lw.WriteLine("Found" & " , " & TempStr) End If Next End Sub End ModuleRE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Below is your code modified to cycle through the visible objects of each drawing sheet looking for Label objects. When one is found it then does the check to see if the required texts exist in the Label and if so writes the drawing sheet name and the label's text to the listing window.
CODE --> VB.NET
' NX 8.0.3.4 Option Strict Off Imports System Imports NXOpen Module NXJournal Dim s As Session = Session.GetSession() Dim dp As Part = s.Parts.Display Dim lw As ListingWindow = s.ListingWindow Sub Main Dim dp As Part = s.Parts.Display Dim textin As String = "XXX" : Dim textin2 As String = "YYY" Dim dwgs As Drawings.DrawingSheetCollection dwgs = dp.DrawingSheets Dim Labelstring() As String If Not lw.IsOpen Then lw.Open() For Each sheet As Drawings.DrawingSheet In dwgs sheet.Open Dim dos() As DisplayableObject=sheet.View.AskVisibleObjects For Each ado As DisplayableObject In dos If Not TypeOf ado Is NXOpen.Annotations.Label Then Continue For Dim a_Label As NXOpen.Annotations.Label=DirectCast(ado,NXOpen.Annotations.Label) Labelstring = a_Label.GetText() Dim TempStr As String = String.Empty Dim IsValid As Boolean = False For ii As Integer = 0 To Labelstring.Length- 1 If Labelstring(ii).Contains(textin) Or Labelstring(ii).Contains(textin2) Then IsValid = True End If Next If IsValid Then For ii As Integer = 0 To Labelstring.Length- 1 If Not String.IsNullOrEmpty(TempStr) Then TempStr = TempStr & ";" & Labelstring(ii) Else TempStr = Labelstring(ii) End If Next lw.WriteLine("Found '" & sheet.Name & ";" & TempStr & "'") End If Next Next End Sub End ModuleGraham Inchley, Systems Developer.
NX6, NX8.5(testing)
www.sandvik.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
www.nxjournaling.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Your code works like a charm
I would prefer to search for the "text to find" in the label.colletction instead on the displayed objects for each sheet...
Journal running time will be reduced to seconds....
Thanks Cowski
Thanks for your input from the GTAC, the reference code in the GTAC solution is preferred for the User selected objects...
I'm not sure, how to use those codes in my journal... (i'm a newbie here)
I would thanks and appreciate, if you can help me with a journal without looping sheets and returning sheet.name of the label..
Meanwhile i'll also work on my journal for improvements...
Thanks in Advance...
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Code written by Amy Webster of GTAC fame.
CODE
' This function will work for: ' an object which "Resides on drawing" or is "View Dependent In" a DraftingView ' a DraftingView ' a DrawingSheet.View ' Returns Nothing for all other (ie. model mode) objects Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet Dim theView As View = TryCast(theObject, View) If Not theView Is Nothing Then Dim sheetTag As Tag = Nothing Try theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag) Return NXObjectManager.Get(sheetTag) ' the drawing it is on Catch ex As NXException Return Nothing ' it is a model view End Try End If Dim viewName As String = Nothing Dim status As Integer = Nothing Try theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName) Catch ex As NXException Return Nothing End Try If status = 0 Then Return Nothing ' it is a model mode object Dim viewTag As Tag = Nothing theUFSession.View.AskTagOfViewName(viewName, viewTag) Dim viewType As Integer = Nothing Dim viewSubtype As Integer = Nothing theUFSession.View.AskType(viewTag, viewType, viewSubtype) If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view Dim drawingTag As Tag = Nothing theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag) Return NXObjectManager.Get(drawingTag) ' the drawing it is on! End Functionwww.nxjournaling.com
RE: Help me with a Journal to report the text strings in a Multisheet drawing (label or notes)
Finally i was able to compile the journal which works 100% persent to match my requirement.. Obsivously taking less time for excution also...
Now the journal running time is reduced to 2 sec from 20 min earlier for 45 sheet drawing.
Here is detailed function of the Journal..
The journal searches for two text stings in all Notes and labels of a multisheet drawing, and reports the Text stings with page number..
CODE -->
'NX 8.0.3.4 Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Annotations Module NXJournal Dim theSession As Session = Session.GetSession() Dim theUFSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim dp As Part = theSession.Parts.Display Dim lw As ListingWindow = theSession.ListingWindow Sub Main Dim lbs As NXOpen.Annotations.LabelCollection = dp.Labels Dim nts As NXOpen.Annotations.NoteCollection = dp.Notes Dim textin As String = "xxx" : Dim textin2 As String = "yyy" Dim dwgs As Drawings.DrawingSheetCollection dwgs = dp.DrawingSheets Dim Labelstring() As String Dim Notestring() As String If Not lw.IsOpen Then lw.Open() For Each a_Label As NXOpen.Annotations.Label In lbs Labelstring = a_Label.GetText() Dim TempStr As String = String.Empty Dim IsValid As Boolean = False Dim theDrawingSheet As Drawings.DrawingSheet = AskDrawingSheet(a_Label) For ii As Integer = 0 To Labelstring.Length- 1 If Labelstring(ii).Contains(textin) Or Labelstring(ii).Contains(textin2) Then IsValid = True End If Next If IsValid Then For ii As Integer = 0 To Labelstring.Length- 1 If Not String.IsNullOrEmpty(TempStr) Then TempStr = TempStr & " " & Labelstring(ii) Else TempStr = Labelstring(ii) End If Next lw.WriteLine(theDrawingSheet.name & ", " & TempStr) End If Next For Each a_Note As NXOpen.Annotations.Note In nts Notestring = a_Note.GetText() Dim TempStr As String = String.Empty Dim IsValid As Boolean = False Dim theDrawingSheet As Drawings.DrawingSheet = AskDrawingSheet(a_Note) For ii As Integer = 0 To Notestring.Length- 1 If Notestring(ii).Contains(textin) Or Notestring(ii).Contains(textin2) Then IsValid = True End If Next If IsValid Then For ii As Integer = 0 To Notestring.Length- 1 If Not String.IsNullOrEmpty(TempStr) Then TempStr = TempStr & " " & Notestring(ii) Else TempStr = Notestring(ii) End If Next lw.WriteLine(theDrawingSheet.name & ", " & TempStr) End If Next End Sub Function AskDrawingSheet(ByVal theObject As TaggedObject) As Drawings.DrawingSheet Dim theView As View = TryCast(theObject, View) If Not theView Is Nothing Then Dim sheetTag As Tag = Nothing Try theUFSession.Draw.AskDrawingOfView(theView.Tag, sheetTag) Return NXObjectManager.Get(sheetTag) ' the drawing it is on Catch ex As NXException Return Nothing ' it is a model view End Try End If Dim viewName As String = Nothing Dim status As Integer = Nothing Try theUFSession.View.AskViewDependentStatus(theObject.Tag, status, viewName) Catch ex As NXException Return Nothing End Try If status = 0 Then Return Nothing ' it is a model mode object Dim viewTag As Tag = Nothing theUFSession.View.AskTagOfViewName(viewName, viewTag) Dim viewType As Integer = Nothing Dim viewSubtype As Integer = Nothing theUFSession.View.AskType(viewTag, viewType, viewSubtype) If viewType = 0 Then Return Nothing ' it is view dependent in a modeling view Dim drawingTag As Tag = Nothing theUFSession.Draw.AskDrawingOfView(viewTag, drawingTag) Return NXObjectManager.Get(drawingTag) ' the drawing it is on! End Function End Module