ilogic export iAssembly factory member bom

ilogic export iAssembly factory member bom

gordon
Participant Participant
603 Views
1 Reply
Message 1 of 2

ilogic export iAssembly factory member bom

gordon
Participant
Participant

I am trying to export the BOM for each iAssembly member.  The numbers are correct, but the export includes all members and the output format is difficult to parse.

 

Can someone help me modify my function to end up with a spreadsheet that has part number and total quantities for each sub component? 

 

Imports File = System.IO.File
Imports Path = System.IO.Path
Imports System.Threading

Sub Main()

	Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	
	If oDef.IsiAssemblyFactory
	
		Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
		Dim memberCacheDir As String = oFactory.MemberCacheDir
		Dim oFactoryTableRows as iAssemblyTableRows = oFactory.TableRows
		Dim oRow As iAssemblyTableRow
		
		' Create progress bar
		Dim iStepCount As Long = oFactoryTableRows.Count + 1
		Dim oProgressBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(
			False,
			iStepCount,
			"Generating Member PDFs",
			False
		)
		oProgressBar.Message = "Preparing to export member BOM files"
		oProgressBar.UpdateProgress
		
	
		' Loop through each row and generate the BOM
		Try
			' Disable screen updating for speed
			ThisApplication.ScreenUpdating = False
			
			' Disable user interaction to prevent complications
			ThisApplication.UserInterfaceManager.UserInteractionDisabled = True
			
			For Each oRow In oFactoryTableRows
				Dim memberName As String = oRow.MemberName
				
				' Change the active row
				iAssembly.ChangeRow("", memberName)
				
				' Access mass property to force physical properties to update
				Dim mass As Double = oDef.MassProperties.Mass
				
				' Generate the member and file, (overwrites member file or creates new file)
				oFactory.CreateMember(oRow)
				
				' Save changes to active row
				RuleParametersOutput()
				InventorVb.DocumentUpdate()
				oDoc.Save
				
				' Generate the BOM
												
				oProgressBar.Message = "Generating BOM for member: " & 
									   memberName & vbNewLine & "Member " & oRow.Index &
									   " of " & oFactoryTableRows.Count
				
				Dim oBOM As BOM = oDef.BOM
				Dim oBOMView As BOMView
				
				oBOM.StructuredViewFirstLevelOnly = False
				oBOM.StructuredViewEnabled = True				
    			oBOMView = oBOM.BOMViews.Item("Structured")
				oBOMView.iAssemblyMemberName = memberName
				
				
				
				
				' Determine output name
				Dim sFname As String = Path.Combine(memberCacheDir, memberName & "-BOM.xls")
				
				' Export BOM
				oBOMView.Export(sFname, kMicrosoftExcelFormat, oOptions)
				
				' Announce progress to user
				oProgressBar.UpdateProgress
				
			Next
			
		Catch e As Exception
			
			Beep()
			MessageBox.Show("Failed to save Member BOM" & vbNewLine & e.ToString, "ERROR")
		
		Finally
			
			' always re-enable Screen Update and User Interaction
			ThisApplication.ScreenUpdating = True
			ThisApplication.UserInterfaceManager.UserInteractionDisabled = False
			
			' close the progress bar
		    oProgressBar.Close
		
		End Try
		
		MessageBox.Show("Saved Member BOMs", "SUCCESS")
		
	Else
	
		MessageBox.Show("Could Not Export iAssembly Member BOMs. Assembly not iAssembly Factory!", "FAILED")
	
	End If
	
End Sub

 

0 Likes
604 Views
1 Reply
Reply (1)
Message 2 of 2

gordon
Participant
Participant

I decided to move forward and make it look like I need for now using the excel vba api.  If anyone has a simpler route, please let me know as I would appreciate simplicity vs the raw power of the excel api for the sake of readability

0 Likes