VB API to add custom IProperties to BOM

VB API to add custom IProperties to BOM

j.romoYDW7Q
Contributor Contributor
60 Views
2 Replies
Message 1 of 3

VB API to add custom IProperties to BOM

j.romoYDW7Q
Contributor
Contributor

Hello, I have a bit of an issue. I can't handle adding properties to the BOM columns on Parts Only. This is my error, and below is the code. Any hints or help is apreciated.

errors 31.png

  Private Sub btnAddCustomPropsToBOM_Click(sender As Object, e As EventArgs)
      Try
          Dim oDoc As AssemblyDocument = TryCast(_inventorApp.ActiveDocument, AssemblyDocument)
          If oDoc Is Nothing Then
              MessageBox.Show("Active document is not an assembly.", "Error")
              Return
          End If

          Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
          oBOM.PartsOnlyViewEnabled = True

          ' Ensure the "Parts Only" BOM view exists
          Dim oBOMView As BOMView = Nothing
          Try
              oBOMView = oBOM.BOMViews.Item("Parts Only")
          Catch
              MessageBox.Show("The 'Parts Only' BOM view is not available.", "Error")
              Return
          End Try

          ' List of standard custom iProperties to always add as BOM columns
          Dim standardProps As String() = {
              "Ancho", "Tipo_Parte", "Proveedor", "Nombre_Parte", "CostoLaser", "TestGithub"
          }

          Dim addedCount As Integer = 0
          Dim alreadyInBOM As New List(Of String)
          For Each propName In standardProps
              Try
                  oBOMView.BOMColumns.Add(2, propName) ' 2 = User Defined Property
                  addedCount += 1
              Catch ex As Exception
                  alreadyInBOM.Add(propName)
              End Try
          Next

          Dim msg As String = $"Added {addedCount} custom iProperties to the BOM."
          If alreadyInBOM.Count > 0 Then
              msg &= vbCrLf & "Already present or could not be added: " & String.Join(", ", alreadyInBOM)
          End If
          MessageBox.Show(msg, "Result")
      Catch ex As Exception
          MessageBox.Show("Error adding custom iProperties to BOM: " & ex.Message)
      End Try
  End Sub

 

0 Likes
Accepted solutions (1)
61 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @j.romoYDW7Q.  I do not believe that we have the ability to add new columns to the assembly BOM for specific standard or custom iProperties by code yet.  Within your code example, the following line of code:

oBOMView.BOMColumns.Add(2, propName) ' 2 = User Defined Property

...is likely throwing an error, but that error is being suppressed by the Try...Catch statement.  This is because there is no BOMView.BOMColumns property, or Add method for columns.  As far as I know, the only way we can customize which columns we want included in our assembly BOM by code, is to use the BOM.ImportBOMCustomization method, after we have already exported a BOM customization that was set-up the way we want it.  So, those columns likely have to be added manually, then export that customization to an external XML file, so that if you want to use the same columns again in another similar assembly, you can import that customization to get it the same as before.

BOM

BOMView

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

j.romoYDW7Q
Contributor
Contributor

Thanks for the clarification on this issue @WCrihfield, I will go with the XML route.
Thanks

0 Likes