Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get ComponentDefinition from Parts List

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
rikard.nilsson
838 Views, 4 Replies

Get ComponentDefinition from Parts List

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

4 REPLIES 4
Message 2 of 5
ludesroc
in reply to: rikard.nilsson

 

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

Ludesroc
Message 3 of 5
rikard.nilsson
in reply to: ludesroc

Hi Ludesroc,

 

What a rookie misstake!! 🙂

Thanks for pointing it out...

 

/Rikard

Message 4 of 5
Lesoux
in reply to: rikard.nilsson

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

Win10 x64
Xeon E5-1630
32 Gb RAM
Quadro K5200

Inventor 2020.3.4, Build 373
Message 5 of 5

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. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report