Item Number Custom Balloons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK so I thought I'd found what I was looking for. I found this http://cadsetterout.com/inventor-tutorials/autodesk-inventor-creating-coordinated-bom-for-large-asse...
Then I saw in the comments a way to automate it.... But...
The code:
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
... when edited to say #ITEM and ItemNumber etc doesn't quite work.
I have some iparts and it doesn't push the item number to the parts.. So I looked again.
I found this code:
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = kAssemblyDocumentObject Then For Each docFile In openDoc.AllReferencedDocuments If docFile.IsModifiable = True Then Dim assemblyDoc As AssemblyDocument assemblyDoc = openDoc Dim assemblyDef As AssemblyComponentDefinition assemblyDef = assemblyDoc.ComponentDefinition Dim partQty As ComponentOccurrencesEnumerator partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile) Dim customPropSet As PropertySet Dim customProp As Inventor.Property Dim propertyName As String Dim propertyValue As Integer customPropSet = docFile.PropertySets.Item("Inventor User Defined Properties") propertyName = "TotalQty" Try propertyValue = customPropSet.Item(propertyName).Value If PartQty.Count <> propertyValue Then customPropSet.Item(propertyName).Value = PartQty.Count End If Catch ex As Exception customProp = customPropSet.Add(PartQty.Count, propertyName) End Try End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
This time I just ran the code as it came. It pushed the custom property through to every part file! Brilliant!!
Only this time it didn't create the custom iproperty and when I tried to change it to item number it just fell on its face.
I've tried my best to mesh the two codes in the hope of getting it working but I can't figure it.
Here is my mess as it stands:
Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = kAssemblyDocumentObject Then For Each docFile In openDoc.AllReferencedDocuments If docFile.IsModifiable = True Then Dim assemblyDoc As AssemblyDocument assemblyDoc = openDoc Dim assemblyDef As AssemblyComponentDefinition assemblyDef = assemblyDoc.ComponentDefinition Dim oBOM As BOM = assemblyDef.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) Next Dim item As ComponentOccurrencesEnumerator item = oBOMRow.ItemNumber Dim customPropSet As PropertySet Dim customProp As Inventor.Property Dim propertyName As String Dim propertyValue As Integer customPropSet = docFile.PropertySets.Item("Inventor User Defined Properties") propertyName = "#ITEM" Try propertyValue = customPropSet.Item(propertyName).Value customPropSet.Item(propertyName).Value = item Catch ex As Exception customProp = customPropSet.Add(item, propertyName) End Try End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
It's not good I know so don't all jump on me.
Is there anyone out there that might be able to get to the bottom of this one for me?
Thanks in advance