How can I restrict iLogic BoM Export to a particular Model State? Now I get data from all of them.

How can I restrict iLogic BoM Export to a particular Model State? Now I get data from all of them.

checkcheck_master
Advocate Advocate
849 Views
4 Replies
Message 1 of 5

How can I restrict iLogic BoM Export to a particular Model State? Now I get data from all of them.

checkcheck_master
Advocate
Advocate

How can I restrict iLogic BoM Export to a particular Model State?

Now I get from each Model State a column with QTY/Item QTY numbers.

0 Likes
Accepted solutions (1)
850 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @checkcheck_master.  I honestly have not tried this yet, but I know that the BOMView object has a ModelStateMemberName property, which is ReadOnly, and reflects whichever ModelState is currently 'active'.  Have you tried simply activating the one specific ModelState object directly, then just make sure that BOMView.ModelStateMemberName property is reflecting the right ModelState before using the BOMView.Export() method.  Then if necessary, use a loop to activate the next ModelState object, then to the next BOMView.Export.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @checkcheck_master 

 

In addtion to the previous suggestion, here is an example that post processes the exported information to keep only one Model State (in the example it's only keeping one called "Master")

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/export-bom-with-ilogic-inventor-2022...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 5

checkcheck_master
Advocate
Advocate

Thank you both for your response.

@WCrihfield, I've tried your suggestion but can't figure out which Model State a BoM should be exported from.

 

@Curtis_Waguespack , that is indeed an option, the columns you do not want to delete.

 

See image, noteworthy that when you manually export a BoM you only get the BoM of the Model State you are in at that moment.
I would expect an option via the API for 'Filter Member Columns'.

Message 5 of 5

MartinJezek
Contributor
Contributor

Hi @checkcheck_master 

 

The solution to your problem is the code below which I put together inspired by the above suggested solutions of @Curtis_Waguespack and @WCrihfield :

 

' Define the active document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

' Access the Bill of Materials and tweak ad lib
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = True
oBOM.StructuredViewEnabled = True

' Access BOM view structured
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")

' This gets name of the active model state
' It is for filtering later in the For Loop
Dim oColName As String
oColName = "QTY (" & oBOMView.ModelStateMemberName & ")"

' Export BOM to file
' Modelstate names can have symbols that file names would not allow
' Change to your liking
oBOMView.Export("BOM_XYZ.xls", kMicrosoftExcelFormat)

' This navigates to the new file
Dim oFile As String
oFile = ThisDoc.Path & "\" & "BOM_XYZ.xls"

' Define Excel objects
Dim excelApp As Object = CreateObject("Excel.Application")
excelApp.Visible = False
excelApp.DisplayAlerts = False

' Checks if file exists
If Dir(oFile) <> "" Then
    Dim oWB As Object = excelApp.Workbooks.Open(oFile)
    Dim oWS As Object = oWB.Worksheets(1)

    ' Loop through columns in reverse
	' That is because the active model state might not be the first
	' If you deleted collumns before the active comes up
	' The indexing would not work correctly
	' This mitigates that problem
    For iCol = oWS.UsedRange.Columns.Count To 1 Step -1
        Dim oCellValue As String = oWS.Cells(1, iCol).Value
        If oCellValue Is Nothing Or oCellValue = "" Then Continue For

		' Here we make use of the Active Model state name created earlier
        If oCellValue.Contains(oColName) Then
		' This gives the collumn of the quantities in the Active model state
		' the name you want, in my case QTY
            oWS.Cells(1, iCol).Value = "QTY"
			
		' This next segment deletes all the other model state quantities
        ElseIf oCellValue.Contains("QTY") Then
            oWS.Columns(iCol).EntireColumn.Delete
        End If
    Next

    ' Autofit columns and save
    oWS.Columns.AutoFit()
    oWB.Save()
    oWB.Close()
End If

excelApp.Quit()
excelApp = Nothing

 

Generally, it is a workaround. Normally, I would export directly to .txt file which I need for further processing.

 

I use the excel just as a step for debugging thanks to its orderliness and ease of editing. But I would prefer implementation of the BOM filtering by Active Model State directly for the export in these formats in ThisBOM.Export(“BOMViewName”, filename, format):

  • kMicrosoftAccessFormat = Microsoft Access
  • kMicrosoftExcelFormat = Microsoft Excel
  • kdBASEIVFormat = dBASE IV
  • kdBASEIIIFormat = dBASE III
  • kTextFileTabDelimitedFormat = Text File Tab Delimited
  • kTextFileCommaDelimitedFormat = Text File Comma Delimited
  • kUnicodeTextFileTabDelimitedFormat = Unicode Text File Tab Delimited
  • kUnicodeTextFileCommaDelimitedFormat = Unicode Text File Comma Delimited

 

I am currently in 2023.5.1, is it maybe already implemented or planned to be in the newer releases? @johnsonshiue 

0 Likes