Hey Guys!
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.Generic
Imports NXOpen
Imports NXOpen.UF
Public Class Label
Public Property AssemblyName As String
Public Property AssemblyMaterial As List(Of String)
End Class
Public Class LabelCollection
Public PIN As String
Public Property Initials As String
Public Property ImplantName As String
Public Property LabelSet As New List(Of Label)
End Class
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 As New LabelCollection
'--------------------------------------
' Variable Declirations for Tabel Extraction
'--------------------------------------
Dim myTabNotes As New 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)
End Sub
Sub FindTabularNotes(ByRef tagList As List(Of Tag), lw As ListingWindow)
Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
Dim NxType As Integer
Dim NxSubtype As Integer
Dim rowTag As Tag = Nothing
Dim colTag As Tag = Nothing
Dim cellTag As Tag = Nothing
Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
If tmpTabNote <> NXOpen.Tag.Null Then
theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, NxType, NxSubtype)
If NxSubtype = UFConstants.UF_tabular_note_subtype Then
theUfSession.Tabnot.AskNthRow(tmpTabNote, 0, rowTag)
theUfSession.Tabnot.AskNthColumn(tmpTabNote, 0, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
Dim cellText As String = ""
Dim evalCellText As String = ""
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)
End If
End If
End If
Loop Until tmpTabNote = NXOpen.Tag.Null
End Sub
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 = Nothing
Dim colTag As Tag = Nothing
Dim cellTag As Tag = Nothing
Dim numRows As Integer = 0
Dim numCols As Integer = 0
Dim tempLabel As New Label
Dim tempName As String = ""
Dim tempMaterialList As New List(Of String)
Dim cellText As String = ""
Dim evalCellText As String = ""
For z As Integer = 0 To 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 As Integer = 2 To 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()
End If
If cellText <> "" Then
tempName = cellText
End If
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 <> "" And Not tempMaterialList.Contains(cellText) Then
tempMaterialList.Add(cellText)
lw.WriteLine("The material stored is " & cellText) 'for testing purposes
Else
lw.WriteLine("Material already in List")
End If
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
End If
Next
End Sub
Sub FindTitleBlockInformation(ByRef tagList As LabelCollection)
'--------------------------------------
' Finds the title bocks in the sessions
'--------------------------------------
Dim titleblocks1(3) As Annotations.TitleBlock
Dim 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 As string
PIN = titleBlockCellBuilder1.EditableText
Dim INITIALS As string
INITIALS = titleBlockCellBuilder2.EditableText
Dim ImplantName As string
ImplantName = titleBlockCellBuilder3.EditableText
tagList.PIN = PIN
tagList.Initials = INITIALS
tagList.ImplantName = ImplantName
End Sub
End Module
re: sheet of annotation
Here is some code from GTAC that determines which sheet an annotation resides on. You should be able to check your tabular notes and ignore those on sheets that you are not interested in.
http://nxjournaling.com/comment/1095#comment-1095
What about by visible layers
Is there a way to limit the search to visible layers? I have found a way to limit the information to sheet already but I am finding a few different sheets that some have decided to put in non-visible layers rather than delete.
re: search visible layers
That will be up to you as the programmer. The API gives you the tools to check the layer status and the layer of the given object. You can write your own function/sub to process or return the objects on a given layer; this function/sub can then be reused in future projects as needed.
I don't know of a single API command that will do it all for you.
Is there an API command that
Is there an API command that will return if an object is currently set to visible? If so then I can easily add that into my loop. But I wouldn't even know where to start with finding out if it was.
re: hidden object
There are at least two reasons why an object would not be visible in the modeling view:
1) It has been hidden (or "blanked" in the older terminology). If the object inherits from the "displayable object" class, you can use the .IsBlanked, .Blank, and .Unblank properties/methods to query and control the visibility.
2) The layer the object is on has been made invisible. You can use the layer manager (available through the part object) to query and change the layer status (.GetState, .GetStates, .ChangeStates, etc).
The "layer visible in view" command or "view dependent edit" can also be used to hide an object, but it is best practice to limit these to the drafting application and not use them in the modeling application.
It would be because the layer
It would be because the layer is set to invisible. Is there a property which I can query to check if it's set to invisible? Then I can add that check into my loops.
re: layer state
The layer collection's .GetState method can help you determine if the layer is hidden or visible. See the code in the following link for an example (found in the second code block after the "skip bodies on invisible layer" comment):
http://nxjournaling.com/comment/3582#comment-3582
Ive tried this in the
Ive tried this in the following implementation previously.
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
workPart.Layers.GetState(tmpTabNote.Layer) <> Layer.State.Hidden
It informs me that Layer is not a member of NXOpen.Tag
So I thought I couldnt use this. I am implementing it in the incorrect way?
re: tmpTabNote
In your code above, tmpTabNote is defined as a Tag (rightly so, for how it is being used). You can get the tabular note object from its tag by using the NXUtilities functions like below:
dim tmpTabNoteObj as displayableObject
tmpTabNoteObj = NXOpen.Utilities.NXObjectManager.Get(tmpTabNote)
You can then check the layer status of the tmpTabNoteObj.
Ahh I see. Where do you ifnd
Ahh I see. Where do you ifnd all this information? I have been trying to troll around the api file for hours and yet it all seems so confusing and I cant find the definitions I want. Any advice?
So Im not sure what a Tag is (I'll look it up in the API and hope it makes sense), but that line you have there is getting the object for the tmpTabNote? Is that right?
re: tag
The NXOpen .net API is still a work in progress; it is an updated version of the older C/C++ API where almost everything was done with functions (the API was not object oriented). Some of these older functions have not (yet) been converted over to the .net OOP way of doing things; however, these functions are still available for use as "wrapped" function calls. The main way of working with NX objects in the older API was by using its unique identifier, or "tag". Instead of passing objects to functions, the tag would be passed and NX would perform the specified actions on the NX object. Tags are still very important when using the "wrapped" function calls.
Everything that I know about the NX API, I've learned by: looking at other people's code, studying the programming help docs, writing code, and asking questions in forums. You can find links to other bits of code and forums here:
http://nxjournaling.com/content/resources
One of the reasons that I started this website was because the API documentation does not offer much in the way of explanation or code examples. If you have a suggestion for a future article, please send it to: info@nxjournaling.com