So I've almost managed to finish this Journal. I have it cycling through my drawings, finding tables and storing them. 2 problems though.
1) Its still finding a table that it doesnt seem to like. I have the function looking at the first cell of the table to check for a name. I seem to have found a table which does not have that cell. What kind of table doesnt have asingle cell and how can I exclude it form the search? Or is there a was to handle that error and tell it to skip that table and keep going? I think the later would be easier to do
2) It currently goes through every sheet in the drawing, which it really doesn't need to do since all the information I require is on the first sheet. Is there a way to limit the sheets it is searching in?
Here is the code for reference. I will post it to the fourm in its finished form once I finally get it working 100%
Option Strict Off
Imports System
Imports System.Collections.GenericImports NXOpen
Imports NXOpen.UF
PublicClass Label
PublicProperty AssemblyName AsString
PublicProperty AssemblyMaterial As List(OfString)
EndClass
PublicClass LabelCollection
Public PIN AsString
PublicProperty Initials AsString
PublicProperty ImplantName AsString
PublicProperty LabelSet AsNew List(Of Label)
EndClass
Module Label_Information_Extraction
Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession()Dim workPart As Part = theSession.Parts.Work
Sub Main()
'--------------------------------------' Opens the Listing Window'--------------------------------------
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'--------------------------------------' Variable Declirations for Tible Block Extraction'--------------------------------------
Dim PatientLabels AsNew LabelCollection
'--------------------------------------' Variable Declirations for Tabel Extraction'--------------------------------------
Dim myTabNotes AsNew List(Of Tag)
'--------------------------------------' Finds the FOUR tables we are interested in and store them in the list of Tag's myTabNotes'--------------------------------------
FindTabularNotes(myTabNotes, lw)
'--------------------------------------' States what we found with the Find Tablare notes section'--------------------------------------
lw.WriteLine("Number of tabular notes found: "& myTabNotes.Count.ToString)
lw.WriteLine("")
'lw.WriteLine("First tabular note info:")'lw.WriteLine("")
'Dim numSections As Integer = 0'theUfSession.Tabnot.AskNmSections(myTabNotes.Item(0), numSections)'lw.WriteLine("Number of sections in tabular note: " & numSections.ToString)
'Dim numRows As Integer = 0'theUfSession.Tabnot.AskNmRows(myTabNotes.Item(0), numRows)'lw.WriteLine("Number of rows in tabular note: " & numRows.ToString)
'Dim numCols As Integer = 0'theUfSession.Tabnot.AskNmColumns(myTabNotes.Item(0), numCols)'lw.WriteLine("Number of columns in tabular note: " & numCols.ToString)'lw.WriteLine("")
'--------------------------------------' Finds the two tables we are interested in and store them in the list of Tag's myTabNotes'--------------------------------------
lw.WriteLine("Searching in the Tabular note now")
TableLabelInformationExtract(myTabNotes,lw, PatientLabels)
lw.WriteLine("The PIN is "& PatientLabels.PIN)
lw.WriteLine("The Patient Initials are "& PatientLabels.Initials)
lw.WriteLine("The Implant is a "& PatientLabels.ImplantName)
EndSub
Sub FindTabularNotes(ByRef tagList As List(Of Tag), lw As ListingWindow)
Dim tmpTabNote As NXOpen.Tag= NXOpen.Tag.NullDim NxType AsIntegerDim NxSubtype AsIntegerDim rowTag As Tag =NothingDim colTag As Tag =NothingDim cellTag As Tag =Nothing
Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
If tmpTabNote <> NXOpen.Tag.NullThen
theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, NxType, NxSubtype)
If NxSubtype = UFConstants.UF_tabular_note_subtypeThen
theUfSession.Tabnot.AskNthRow(tmpTabNote, 0, rowTag)
theUfSession.Tabnot.AskNthColumn(tmpTabNote, 0, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)Dim cellText AsString=""Dim evalCellText AsString=""
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
If cellText ="IMPLANT COMPONENTS"OR cellText ="CUSTOM INSTRUMENTS"OR cellText ="PIN"OR cellText ="IMPLANT TYPE"Then
lw.WriteLine("The table being stored Contains "& cellText)
tagList.Add(tmpTabNote)
EndIf
EndIf
EndIf
Loop Until tmpTabNote = NXOpen.Tag.Null
EndSub
Sub TableLabelInformationExtract(tagList As List(Of Tag), lw As ListingWindow, ByRef PatientInformation As LabelCollection)
'--------------------------------------' Variable Declirations for Tible Block Information Extraction'--------------------------------------
Dim rowTag As Tag =NothingDim colTag As Tag =NothingDim cellTag As Tag =NothingDim numRows AsInteger=0Dim numCols AsInteger=0Dim tempLabel AsNew Label
Dim tempName AsString=""Dim tempMaterialList AsNew List(OfString)Dim cellText AsString=""Dim evalCellText AsString=""
For z AsInteger=0To tagList.Count-1
theUfSession.Tabnot.AskNmColumns(tagList.Item(z), numCols)
theUfSession.Tabnot.AskNmRows(tagList.Item(z), numRows)
theUfSession.Tabnot.AskNthRow(tagList.Item(z), 0, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 0, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
If cellText ="IMPLANT COMPONENTS"Or cellText ="CUSTOM INSTRUMENTS"Then
For y AsInteger=2To numRows -1
theUfSession.Tabnot.AskNthRow(tagList.Item(z), y, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 5, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
lw.WriteLine("We are in row "& y)'for testing purposes
If cellText <>""And cellText <> tempName Then
tempLabel.AssemblyName= tempName
tempLabel.AssemblyMaterial= tempMaterialList
PatientInformation.LabelSet.Add(tempLabel)
tempName =""
tempMaterialList.Clear()EndIf
If cellText <>""Then
tempName = cellText
EndIf
theUfSession.Tabnot.AskNthRow(tagList.Item(z), y, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 3, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
lw.WriteLine("The material present is "& cellText)'for testing purposes
If tempName <>""AndNot tempMaterialList.Contains(cellText)Then
tempMaterialList.Add(cellText)
lw.WriteLine("The material stored is "& cellText)'for testing purposes
Else
lw.WriteLine("Material already in List")EndIf
Next
ElseIf cellText ="PIN"Then
theUfSession.Tabnot.AskNthRow(tagList.Item(z), 1, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 0, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
PatientInformation.PIN= cellText
theUfSession.Tabnot.AskNthRow(tagList.Item(z), 1, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 1, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
PatientInformation.Initials= cellText
ElseIf cellText ="IMPLANT TYPE"Then
theUfSession.Tabnot.AskNthRow(tagList.Item(z), 1, rowTag)
theUfSession.Tabnot.AskNthColumn(tagList.Item(z), 0, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)
theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
PatientInformation.ImplantName= cellText
EndIf
Next
EndSub
Sub FindTitleBlockInformation(ByRef tagList As LabelCollection)
'--------------------------------------' Finds the title bocks in the sessions'--------------------------------------
Dim titleblocks1(3)As Annotations.TitleBlockDim titleBlock1 As Annotations.TitleBlock=CType(workPart.FindObject("HANDLE R-147862"), Annotations.TitleBlock)
titleblocks1(0)= titleBlock1
Dim titleBlock2 As Annotations.TitleBlock=CType(workPart.FindObject("HANDLE R-169015"), Annotations.TitleBlock)
titleblocks1(1)= titleBlock2
Dim titleBlock3 As Annotations.TitleBlock=CType(workPart.FindObject("HANDLE R-197476"), Annotations.TitleBlock)
titleblocks1(2)= titleBlock3
Dim titleBlock4 As Annotations.TitleBlock=CType(workPart.FindObject("HANDLE R-393572"), Annotations.TitleBlock)
titleblocks1(3)= titleBlock4
Dim editTitleBlockBuilder1 As Annotations.EditTitleBlockBuilder
editTitleBlockBuilder1 = workPart.DraftingManager.TitleBlocks.CreateEditTitleBlockBuilder(titleblocks1)
Dim titleBlockCellBuilderList1 As Annotations.TitleBlockCellBuilderList
titleBlockCellBuilderList1 = editTitleBlockBuilder1.Cells
'--------------------------------------' Finds the cells in the title blocks''--------------------------------------
Dim taggedObject1 As TaggedObject
taggedObject1 = titleBlockCellBuilderList1.FindItem(0)
Dim titleBlockCellBuilder1 As Annotations.TitleBlockCellBuilder=CType(taggedObject1, Annotations.TitleBlockCellBuilder)
Dim taggedObject2 As TaggedObject
taggedObject2 = titleBlockCellBuilderList1.FindItem(1)
Dim titleBlockCellBuilder2 As Annotations.TitleBlockCellBuilder=CType(taggedObject2, Annotations.TitleBlockCellBuilder)
Dim taggedObject3 As TaggedObject
taggedObject3 = titleBlockCellBuilderList1.FindItem(10)
Dim titleBlockCellBuilder3 As Annotations.TitleBlockCellBuilder=CType(taggedObject3, Annotations.TitleBlockCellBuilder)
Dim PIN Asstring
PIN = titleBlockCellBuilder1.EditableText
Dim INITIALS Asstring
INITIALS = titleBlockCellBuilder2.EditableText
Dim ImplantName Asstring
ImplantName = titleBlockCellBuilder3.EditableText
tagList.PIN= PIN
tagList.Initials= INITIALS
tagList.ImplantName= ImplantName
EndSub
EndModule