Hi,
I have a Rule that I want to get the ComponentDefinitions from a row in a Parts List
The problem is that the row
Dim oCompDefs As Any = oRow.ComponentDefinitions
will raise an error in my Try..
In the end I want to get the name of the part that creates the Parts List Row..
I think I will get this with...
oCompDefs.Get_Item(1).Document.FullFileName
But if that is the wrong way I would be happy if you could show me how to det the name of the part
Regards
Rikard
Uncached Rule ItemAndPartNumberInBOM As List
Dim rowVaules As List = {}
ItemAndPartNumberInBOM = {}
Try
Dim oPartList As Any = noValue
oPartList = GetHostObject(PartsList)
Dim i As integer
For i = 1 To oPartList.PartsListRows.Count
Dim oRow As any = oPartList.PartsListRows.Get_Item(i)
Dim j As integer
Try
Dim oCompDefs As Any = oRow.ComponentDefinitions
Catch Error
%%iv_Message("Error")
End Try
For j = 1 To oPartList.PartsListColumns.Count
Dim oCell As any = oRow.Get_Item(j)
rowVaules = rowVaules + {{oPartList.PartsListColumns.Get_Item(j).Title, oCell.Value}}
Next
ItemAndPartNumberInBOM = ItemAndPartNumberInBOM + {rowVaules}
rowVaules = {}
Next
Catch Error
End Try
End Rule
Solved! Go to Solution.
Solved by ludesroc. Go to Solution.
Here's an example...
Uncached Rule ItemAndPartNumberInBOM As List
Dim retList As List = {}
Try
Dim i As Integer
Dim count As Integer
Dim oAssemblyDocument As Any = %%InventorApplication.Documents.get_ItemByname(Me.Model.AssemblyPathname)
Dim oBOM As Any = oAssemblyDocument.ComponentDefinition.BOM
Dim strBOMView As String
If PartsList.Level = :FirstLevelComponents Then
oBOM.StructuredViewEnabled = True
strBOMView = "Structured"
Else
oBOM.PartsOnlyViewEnabled = True
strBOMView = "Parts Only"
End If
Dim oBOMRows As Any = oBOM.BOMViews.get_Item(strBOMView).BOMRows
count = oBOMRows.count
Dim oPartDoc As Any
Dim oBOMRow As Any
For i = 1 To count
oBOMRow = oBOMRows.get_Item(i)
oPartDoc = oBOMRow.ComponentDefinitions.get_Item(1).Document
retList = retList + {{oPartDoc.fullfilename}}
Next
Catch Error
End Try
Return retList
End Rule
Hi Ludesroc,
What a rookie misstake!! 🙂
Thanks for pointing it out...
/Rikard
This code allow me to get item number for the part view on the drawing. Maybe it will be helpfull too.
<%%Category("CustomFunctions"), %%Prompt("...")> _
Function getPListItemNumber(obj As Part, pl As Part) As Any
Dim hostObj As Any = GetHostObject(obj)
Dim partList As Any = GetHostObject(pl)
Dim partListRows As Any = partList.PartsListRows
Dim partListRow As Any
Dim drwBOMRow As Any
Dim BOMRowCompDef As Any
Dim BOMRowRefDocDisplayName As Any
If hostObj.DefinitionDocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
Dim refDocDescObj As Any = hostObj.ReferencedDocumentDescriptor
Dim drwViewRefDocDisplayName As Any = refDocDescObj.DisplayName
For i = 1 To partListRows.Count
partListRow = partListRows.get_Item(i)
For j = 1 To partListRow.ReferencedRows.Count
drwBOMRow = partListRow.ReferencedRows.get_Item(j)
For k = 1 To drwBOMRow.BOMRow.ComponentDefinitions.Count
BOMRowCompDef = drwBOMRow.BOMRow.ComponentDefinitions.get_Item(k)
BOMRowRefDocDisplayName = BOMRowCompDef.Document.DisplayName
If drwViewRefDocDisplayName = BOMRowRefDocDisplayName Then
Return "IT-" + partListRow.get_Item(1).Value
End If
Next
Next
Next
Return "NoValue"
Else
Dim subOccObj As Any = hostObj.SubOccurrences
Dim listItems As List
Dim listFinalItems As List
For i = 1 To subOccObj.Count
Dim refDocDescObj As Any = subOccObj.get_Item(i).ReferencedDocumentDescriptor
Dim drwViewRefDocDisplayName As Any = refDocDescObj.DisplayName
For j = 1 To partListRows.Count
partListRow = partListRows.get_Item(j)
For k = 1 To partListRow.ReferencedRows.Count
drwBOMRow = partListRow.ReferencedRows.get_Item(k)
For l = 1 To drwBOMRow.BOMRow.ComponentDefinitions.Count
BOMRowCompDef = drwBOMRow.BOMRow.ComponentDefinitions.get_Item(l)
BOMRowRefDocDisplayName = BOMRowCompDef.Document.DisplayName
If drwViewRefDocDisplayName = BOMRowRefDocDisplayName Then
listItems = listItems + {partListRow.get_Item(1).Value}
End If
Next
Next
Next
Next
listFinalItems = removeDuplicates(listItems)
Dim result As String = "IT-"
For ij = 1 To length(listFinalItems)
If ij <> length(listFinalItems) Then
result = result + nth(ij, listFinalItems) + ", "
Else
result = result + nth(ij, listFinalItems)
End If
Next
Return result
End If
End Function
I am trying to use this code, but I do not know where I put in my unique file names. I don't know how clear I am being when I say that. What I want to do is a read the parts list and get the item number for that part on the BOM list.