Community
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

More API Control over the BOM

More API Control over the BOM

I would like to see more API control available over the Bill of Materials. My main wish is the ability to add a custom iProperty as a column. My macro to sort the BOM is rendered useless if the custom iProperty column is not added manually (or by template) before hand. Another request I saw while searching the forums is to be able to arrange the column order and add/remove general columns.

9 Comments
Anonymous
Not applicable

I have question for you.
Do you sort by more than one column in your rmacro? I have tried to do sorting with method from API. From what I know, it doesn't work properly.
Can you share your code here or on priv. It will be very helpful for me.

pball
Advisor

I actually just came across that bug, reported it, and had an Autodesk employee confirm it. Though I did find a work around. Since calling out a second or third sort parameter doesn't work you can try sorting the BOM with two separate commands like so. The order is backwards when doing it this way and you might have to play around to make sure it's sorting like you want.

 

Call oBOMView.Sort("Part Number", True)
Call oBOMView.Sort("REQ Type", False)

 

 

Anonymous
Not applicable

Thanks for your answer. Did they tell you when they are planing to remove that bug? It was reported in 2012.

pball
Advisor

The person I was talking with confirmed the bug and said they would log it. It's pointless to ask when a feature/bug fix will happen, either they won't say or they don't even know.

tolgay.hickiran
Advisor

Especially for a specific problem, this is very much needed for us.

 

We are using ilogic to parametrically manipulate our designs and while doing that we also are using Level of Detail representations. If you are not in a "Master" LoD, the API does not let you to get Structured or Parts Only BOM. Because of this, we always count the occurances of the assembly parts to know how many pieces are active/passive.

MechMachineMan
Advisor

I like having more options, but isn't this issue mitigated but importing a BOM customization file before you work with the BOM?

pball
Advisor

MechMachineMan could you please share more info on that? I'm not aware of that or what it can do.

MechMachineMan
Advisor

The method still doesn't EXPORT retaining column order, but that can be mitigated by a simple excel sort.

 

Example VBA snippets below:

 

Public Sub FetchBOM(oBOMDocName As String, oNewXLFileName As String)
    
    On Error Resume Next

    Dim invDoc As Inventor.Document
    Set invDoc = invApp.Documents.ItemByName(oBOMDocName)
    
    If Err.Number <> 0 Then
        MsgBox ("Error in Fetch BOM!")
    End If
    
    Dim oBOM
    Set oBOM = invDoc.ComponentDefinition.BOM

    Call oBOM.ImportBOMCustomization(ActiveWorkbook.Worksheets("CONFIG").Cells(11, "B"))

    oBOM.StructuredViewFirstLevelOnly = False

    oBOM.StructuredViewEnabled = True

    Dim oStructuredBOMView
    Set oStructuredBOMView = oBOM.BOMViews.Item("Structured")
    Call oStructuredBOMView.Sort("Item", True)
    
    Call oStructuredBOMView.Export(oNewXLFileName, 74498, "Sheet1")
    
    If Err.Number <> 0 Then
        MsgBox ("Error Exporting!: " & Err.Number & " :: " & Err.Description)
    End If
End Sub
Private Sub ReorderXLBOM()

    Dim arrColOrder
    Dim ndx
    Dim Found
    Dim counter

    arrColOrder = Array("Item", "QTY", "Part Number", "Description", "Stock Number")
    counter = 1

On Error Resume Next

    For ndx = LBound(arrColOrder) To UBound(arrColOrder)

        'Set Found = xlws.Rows("1:1").Find(arrColOrder(ndx),, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
        Set Found = xlws.Rows("1:1").Find(arrColOrder(ndx), , -4163, 1, 2, 1, False)
    
        If Err.Number <> 0 Then
            MsgBox ("Error With Excel FIND function: " & Err.Number & " :: " & Err.Description & vbLf & vbLf & ndx)
            Err.Clear
        End If

        If Not Found Is Nothing Then
                If Found.Column <> counter Then
                        Found.EntireColumn.Cut
                        xlws.Columns(counter).Insert -4161
                        Application.CutCopyMode = False
                End If
                counter = counter + 1
        End If
    Next
    
    If Err.Number <> 0 Then
            MsgBox ("Reorder Columns Rule Error: " & Err.Number & " :: " & Err.Description & vbLf & vbLf & ndx)
            Err.Clear
    End If
        
End Sub
DRoam
Mentor

I'd like to be able to add/remove/reorder columns using the API as well.

 

I would also like to be able to open the BOM to a specific View using the API:

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea  

Autodesk Design & Make Report