Add custom iProperty to BOM using API

Add custom iProperty to BOM using API

CalvinDay
Enthusiast Enthusiast
6,477 Views
9 Replies
Message 1 of 10

Add custom iProperty to BOM using API

CalvinDay
Enthusiast
Enthusiast

I would like to add a Custom iProperty to the BOM using API.

 

It would mimic the "Add custom iProperty columns" dialog.

0 Likes
Accepted solutions (1)
6,478 Views
9 Replies
Replies (9)
Message 2 of 10

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

As I know, this is not currently supported. Sorry for this.

 

Regards,

Xiaodong Liang

Developer Technical Services

0 Likes
Message 3 of 10

Anonymous
Not applicable

This is how I made it work for myselft.

 

Sub AddProp(oCompDef As ComponentDefinition)

Dim oDesc As Property

On Error Resume Next
' add here the iprop custom you want... as many as you need.


Set oDesc = oCompDef.Document.PropertySets.Item(4).Add("Valeur", "Titre")
Set oDesc = oCompDef.Document.PropertySets.Item(4).Add("Valeur2", "Titre2")


On Error GoTo 0


End Sub


Public Sub BOMQuery()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

   
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    Set oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    
        oBOM.StructuredViewFirstLevelOnly = False
    
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Structured")
       

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        Set oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As ComponentDefinition
        Set oCompDef = oRow.ComponentDefinitions.Item(1)

        
        If TypeOf oCompDef Is VirtualComponentDefinition Then

            
        Else

            Call AddProp(oCompDef)
            
                   
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub



0 Likes
Message 4 of 10

CalvinDay
Enthusiast
Enthusiast

I was trying to add a custom property to a DrawingBOM automatically since I already have the iProperties in the placed parts.

 

What I ended up doing was to change the style library where the custom I properties are already in the Partslist style.

 

Once that was done, just placing the BOM on the drawing showed the corrct columns. However, you do have to run the Inventor Project Editor from the Windows Start menu in order to create a project where you can read/write to the style library.

0 Likes
Message 5 of 10

xiaodong_liang
Autodesk Support
Autodesk Support

hi,

 

As what I understood on the original question, what I meant was: current Inventor API has not exposed the BOM.Columns. So we cannot add a custom column like the UI does (please see attached snapshot). Of course, if the original question is just to add properties to the parts /sub-assemblies, your code is helpful. But these custom iProperties cannot be listed in BOM view until you add them manually by UI.

 

If the question is to add the columns in the final Excel table exported from BOM (by UI or API), you could open the Excel file and add column by Excel API.

 

Regards,

Xiaodong Liang

Developer Technical Services

Message 6 of 10

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution

hi,

 

Are you referring to the ability in Drawing document like the attached snapshot? If yes, please refer to the code below. It addes one column named "aaa" and added the corresponding value from the iProperties of the part.

 

Public Sub test()

 

Dim oPartsList As PartsList
Set oPartsList = ThisApplication.ActiveDocument.SelectSet(1)

 

the value of the rows will be filled in automatically

oPartsList.PartsListColumns.Add kCustomProperty, , "aaa"

  
End Sub

Message 7 of 10

JBerns
Advisor
Advisor

Community,

 

I have searched the forums and the 2019 API help, but still have not found a way to use the API to add a column to the BOM.

 

Has this support been added in Inventor 2021?

 

I am performing a BOM sort using a custom iProperty. If the iProperty column is missing in the BOM, the sort fails. I can error trap for that, but it would be great if I could add the missing iProperty column before sorting.

 

I have also searched forums/Help to determine if a custom iProperty column exists in a BOM, but have been unsuccessful. That way I could trap before an error occurs.

 

Any updates and assistance would be appreciated.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 8 of 10

freesbee
Collaborator
Collaborator

...even if it is very strange that I confirm what Xiaodong has already confirmed, I can confirm it as well 🤣

I was needing exactly the same functionality in a development a few months ago, and I've been struggling like hell to add a custom column to the BOM without succeding. I have asked the Adsk guys and... Xiaodong confirmed me that it is not exposed 😄

Maybe we should make an idea on that? It looks like many users need this!!

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes
Message 9 of 10

DRoam
Mentor
Mentor

A little late, but here is an idea for this: More API Control over the BOM.

 

PS, can Message 6 by Xiaodong please be un-marked as the solution? It's answering a question by a different user about a completely different topic from the original post. (tagging @CGBenner, I assume you're the right guy to notify of this, as our most honorable Community Manager?)

Message 10 of 10

freesbee
Collaborator
Collaborator

...oh, too bad to hear: only 12 votes right now 😢

Maybe that is because the idea is not that "specific"?

So I will start promoting it... now that instance properties will come out I have a free slot in the list of ideas that I support and promote 😀

Thank you @DRoam for finding it out!!

Massimo Frison
CAD R&D // PDM Admin · Hekuma GmbH
0 Likes