Why do iAssembly Factory BOMs give incorrect ComponentOccurance data for inactive BOM lines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to traverse the BOM of an iAssembly Factory assembly with multiple configurations and extract the BOM to a custom data interchange format for our awful ERP system.
I can parse through the BOM rows no problem, but when I go to extract data from "inactive" BOM row (i.e.: from a different line in the iFactory table than is currently active) the data I get out is incorrect.
This presents as follows:
1st BOM line (Active) is Item #1, Name is Part1 '<-Outputs as expected
2nd BOM line (Inactive) is Item#2, Name is Part2 '<- Item # correct "2" but Outputs Part1 Again
3nd BOM line (Inactive) is Item#2, Name is Part3 '<- Item # correct "3" but Outputs Part1 Again
....
37th BOM line (Finally another Active Line) is Item#37, Name is Part37 '<-Outputs correctly again
38th BOM line (Inactive) is Item#38, Name is Part37 '<- Item # correct "37" but Outputs Part37 Again
etc...
I can see this data (Correctly) in "All Members" view of the BOM in inventor. I know the correct data is in there somewhere. How do I get it out? Surely there has to be a better solution than traversing all the instances and ignoring zero qty lines then adding it all together at the end?
Problem lines:
'Traverse the BOM For Each oBOMRow In oAssyBOMRows oComponentOcc = oBOMRow.ComponentOccurrences.Item(1) 'Get first occurrence of each BOM line item to suck out it's parameters. 'MYSTERIOUSLY DOESNT WORK ON iAssembly parts :-/ Just stays stuck on the last "Active" instance instead '<TODO> Add Support for Instance Properties? oComponentName = oComponentOcc.Name
Full Sub minus some excel stuff that I've redacted.:
Sub Main() 'Document Level Variable Definitions Dim oDocType As DocumentTypeEnum = ThisDoc.Document.DocumentType Dim oDocFileName As String = ThisDoc.FileName(False) 'without extension Dim oDocPath As String = ThisDoc.Path 'Assembly Level Variable Definitions Dim oAssyDoc As AssemblyDocument = Nothing Dim oAssyCompDef As AssemblyComponentDefinition = Nothing Dim oAssyName As String = Nothing 'iAssembly Variable Definitions Dim oAssyFactory As iAssemblyFactory = Nothing Dim oFactoryRowCount As Integer = 0 'Default of 0 means NOT a factory 'BOM Variable Definitions Dim oAssyBOM As BOM = Nothing Dim oAssyBOMView As BOMView = Nothing Dim oAssyBOMRows As BOMRowsEnumerator = Nothing 'Components definition variables(Not needed?) 'Dim oAssyComponents As ComponentOccurrences = Nothing 'Dim oAssyComponentsCount As Integer = 0 'Check that this part is an Assembly If oDocType <> DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("This Script is intended for Assemblies ONLY", MessageBoxIcon.Error, "Error - Wrong Document Type") : Exit Sub Else 'If so, Then get Links to Assembly Document Objects oAssyDoc = ThisApplication.ActiveDocument oAssyCompDef = oAssyDoc.ComponentDefinition oAssyName = oAssyDoc.DisplayName If oAssyCompDef.IsiAssemblyFactory Then 'IF factory assembly, then get Factory Object and row Count. oAssyFactory = oAssyCompDef.iAssemblyFactory 'Returns Nothing if not a Factory Assembly oFactoryRowCount = oAssyFactory.TableRows.Count End If ' oAssyComponents = oAssyCompDef.Occurrences ' oAssyComponentsCount = oAssyCompDef.Occurrences.Count oAssyBOM = oAssyCompDef.BOM oAssyBOM.StructuredViewEnabled = True oAssyBOM.StructuredViewFirstLevelOnly = True '<TODO> Add Capabilities for multi-level BOMs. NOTE multilevel BOMS are NOT COMPATIBLE w iFactories. oAssyBOMView = oAssyBOM.BOMViews.Item("Structured") oAssyBOMRows = oAssyBOMView.BOMRows End If 'BOM ITEM Variable Definitions Dim oBOMRow As BOMRow Dim oComponentOcc As ComponentOccurrence = Nothing Dim oComponentDef As ComponentDefinition = Nothing Dim oComponentDoc As Document = Nothing Dim oComponentName As String = Nothing Dim oComponentNameAndPath As String = Nothing Dim oBOMRowItemNum As String = Nothing Dim oComponentPartNumber As String = Nothing 'Dim oComponentDescription As String = Nothing 'Dim oComponentDwgNum As String = Nothing 'Dim oComponentMatl As String = Nothing 'Property Sets of Component Variables 'Dim oInstanceProps As PropertySet = Nothing Dim oSummaryProps As PropertySet = Nothing 'Summary Tab Properties except Manager, Company, and Category Dim oDocumentProps As PropertySet = Nothing 'Only Manager, Company, and Category Dim oDesignTrackingProps As PropertySet = Nothing 'This is the Main one for Project, status, etc... Dim oUserProps As PropertySet = Nothing 'Anything User Added within the child parts themselves. 'oBOMRow.ComponentDefinitions Dim i As Integer = 0 ' Debugging Count Variable Dim j As Integer = 0 ' Debugging Count Variable 'Traverse the BOM For Each oBOMRow In oAssyBOMRows oComponentOcc = oBOMRow.ComponentOccurrences.Item(1) 'Get first occurance of each BOM line item to suck out it's parameters. 'MYSTERIOUSLY DOESNT WORK ON iAssembly parts :-/ Just stays stuck on the last "Active" instance instead '<TODO> Add Support for Instance Properties? oComponentName = oComponentOcc.Name oComponentDoc = oComponentOcc.Definition.Document 'MAGIC Document grabbing undocumented BS oComponentName = oComponentDoc.DisplayName oComponentNameAndPath = oComponentDoc.File.FullFileName oBOMRowItemNum = oBOMRow.ItemNumber 'Get sub-part/assembly stored Properties oSummaryProps = oComponentDoc.PropertySets.Item("Inventor Summary Information") oDocumentProps = oComponentDoc.PropertySets.Item("Inventor Document Summary Information") oDesignTrackingProps = oComponentDoc.PropertySets.Item("Design Tracking Properties") oUserProps = oComponentDoc.PropertySets.Item("Inventor User Defined Properties") oComponentPartNumber = oDesignTrackingProps.Item("Part Number").Value 'Debugging Nonsense If i < 50 Then MsgBox(oComponentOcc.ActiveModelState & " " & oBOMRowItemNum & " " & oBOMRow.ComponentOccurrences.Count & " " & oComponentName) i = i + 1 ' If oComponentPath.Contains("Content Center Files") Then ' '<TODO> STUFF TO LIBRARY PARTS <TODO> ' End If Next