Is there a way to use iLogic to copy a value from the assembly BOM 'Item QTY', and paste it to each part in the assembly as a custom iproperty?
Solved! Go to Solution.
Is there a way to use iLogic to copy a value from the assembly BOM 'Item QTY', and paste it to each part in the assembly as a custom iproperty?
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by A.Acheson. Go to Solution.
By looping through the BomView object ad each Bom Row you can achieve this.
Dim assyDoc As AssemblyDocument = ThisDoc.Document
Dim bom As BOM = assyDoc.ComponentDefinition.BOM
bom.PartsOnlyViewEnabled = True
Dim bView As BOMView = bom.BOMViews.Item("Parts Only")
For Each bRow As BOMRow In bView.BOMRows
If bRow.ComponentDefinitions.Count > 1
'MessageBox.Show("duplicate part #'s")
Continue For
End If
Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
If Not partDoc.IsModifiable Then Continue For
' ilogic iProperty Method.
Try
Dim componentName As String = IO.Path.GetFileName(partDoc.FullFileName)
iProperties.Value(componentName,"Custom", "TOTAL QTY") = bRow.ItemQuantity
Catch
End Try
' ' API PropertySets Method.
' Dim totalQty As Inventor.Property
' Try
' totalQty = partDoc.PropertySets.Item(4).Item("TOTAL QTY")
' totalQty.Value = bRow.ItemQuantity
' Catch
' totalQty = partDoc.PropertySets.Item(4).Add(bRow.ItemQuantity,"TOTAL QTY")
' End Try
Next
By looping through the BomView object ad each Bom Row you can achieve this.
Dim assyDoc As AssemblyDocument = ThisDoc.Document
Dim bom As BOM = assyDoc.ComponentDefinition.BOM
bom.PartsOnlyViewEnabled = True
Dim bView As BOMView = bom.BOMViews.Item("Parts Only")
For Each bRow As BOMRow In bView.BOMRows
If bRow.ComponentDefinitions.Count > 1
'MessageBox.Show("duplicate part #'s")
Continue For
End If
Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
If Not partDoc.IsModifiable Then Continue For
' ilogic iProperty Method.
Try
Dim componentName As String = IO.Path.GetFileName(partDoc.FullFileName)
iProperties.Value(componentName,"Custom", "TOTAL QTY") = bRow.ItemQuantity
Catch
End Try
' ' API PropertySets Method.
' Dim totalQty As Inventor.Property
' Try
' totalQty = partDoc.PropertySets.Item(4).Item("TOTAL QTY")
' totalQty.Value = bRow.ItemQuantity
' Catch
' totalQty = partDoc.PropertySets.Item(4).Add(bRow.ItemQuantity,"TOTAL QTY")
' End Try
Next
Hi @spanky
It likely just tripped over a subassembly in your BOM
I think you can just change line 15
from this:
Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
to this:
Dim partDoc As Document = bRow.ComponentDefinitions(1).Document
Hi @spanky
It likely just tripped over a subassembly in your BOM
I think you can just change line 15
from this:
Dim partDoc As PartDocument = bRow.ComponentDefinitions(1).Document
to this:
Dim partDoc As Document = bRow.ComponentDefinitions(1).Document
Try this one run in assembly.
doc = ThisDoc.Document Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition Dim oBOM As BOM = oAssyDef.BOM oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only") Dim oBOMRow As BOMRow For Each oBOMRow In oBOMView.BOMRows 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition oCompDef = oBOMRow.ComponentDefinitions.Item(1) Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName Dim CompFileNameOnly As String Dim index As Integer = CompFullDocumentName.LastIndexOf("\") CompFileNameOnly = CompFullDocumentName.Substring(index+1) 'MessageBox.Show(CompFileNameOnly) Dim Qty As String Qty = oBOMRow.TotalQuantity iProperties.Value(CompFileNameOnly, "Custom", "PartQty") = Qty Next
Try this one run in assembly.
doc = ThisDoc.Document Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition Dim oBOM As BOM = oAssyDef.BOM oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only") Dim oBOMRow As BOMRow For Each oBOMRow In oBOMView.BOMRows 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition oCompDef = oBOMRow.ComponentDefinitions.Item(1) Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName Dim CompFileNameOnly As String Dim index As Integer = CompFullDocumentName.LastIndexOf("\") CompFileNameOnly = CompFullDocumentName.Substring(index+1) 'MessageBox.Show(CompFileNameOnly) Dim Qty As String Qty = oBOMRow.TotalQuantity iProperties.Value(CompFileNameOnly, "Custom", "PartQty") = Qty Next
Cheers Curtis,
I hadn't allowed for assemblies being inseparable and being in there which is why it tripped up on the part document declaration. The generic document declaration will allow both part documents and assembly document processing.
Cheers Curtis,
I hadn't allowed for assemblies being inseparable and being in there which is why it tripped up on the part document declaration. The generic document declaration will allow both part documents and assembly document processing.
Thank you!
This one worked also, but seems to have pulled the standard QTY data, versus the Item QTY. But thank you for the help also!
This one worked also, but seems to have pulled the standard QTY data, versus the Item QTY. But thank you for the help also!
Can't find what you're looking for? Ask the community or share your knowledge.