Message 1 of 6
Issue when getting total quantity of Parts and Subassemblies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
I'm using a code that gets the total quantity of Parts and Subassemblies. As you know, the BOM View Parts Only only shows total quantity of parts but not the Normal Subassemblies. BOM View Structured shows the total quantity per subassembly but not the total quantity of parts and subassemblies in the whole assembly regardless of the level. My code works well except when my subassemblies are set to a LOD. For instance, my Top Level Assembly is set Custom LOD 'iLogic' and this LOD calls LODs in subassemblies (e.g. Subassembly1(iLogic) - iLogic is the LOD name). Do you know why it doesn't work? if so how can I fix it? Thanks! Here is the code (BTW, I'm traversing the assembly with Referenced Documents)
SyntaxEditor Code Snippet
'***GETS TOTAL QTY OF PARTS AND SUBASSEMBLIES Sub Main() 'Gets the document where this rule is oDoc = ThisDoc.Document ThisDoc.Save 'Makes sure the document is an assembly If oDoc.DocumentType = kAssemblyDocumentObject 'Get all Of the referenced documents. Dim oRefDocs As DocumentsEnumerator oRefDocs = oDoc.AllReferencedDocuments Dim oRefDoc As Document '[ 'GETS THE TOTAL QUANTITY OF COMPONENTS For Each oRefDoc In oRefDocs 'Make sure the file can be edited Try 'Make sure the file can be edited If oRefDoc.IsModifiable = True Then Dim AssyDoc As AssemblyDocument AssyDoc = oDoc 'Gets all assembly occurrences Dim oOccs As ComponentOccurrences oOccs = AssyDoc.ComponentDefinition.Occurrences 'Gets all referenced document occurrences Dim oFileOccs As ComponentOccurrencesEnumerator oFileAllOccs = oOccs.AllReferencedOccurrences(oRefDoc) 'Gets Referenced Doc Custom properties Dim oCustomProps As PropertySet oCustomProps = oRefDoc.PropertySets.Item("Inventor User Defined Properties") 'Gets/adds the custom property 'TotalQty' and gets the Total Quantity Dim oTotalQty As Inventor.Property Try oTotalQty = oCustomProps.Item("TotalQty") Catch oTotalQty = oCustomProps.Add("", "TotalQty") Finally oTotalQty.Value = oFileAllOccs.Count End Try End If Catch 'All instances of the file are suppressed End Try Next End If End Sub