4 Replies Latest reply on May 22, 2017 11:06 AM by Xavier Rodríguez Nieto

    Get part number used in BOM

    Xavier Rodríguez Nieto

      When you insert a BOM in a drawing, one of the parameters you can show is the "PART NUMBER" (probably the most important), the value for the "PART NUMBER" is determined in the configuration of the component and it can be the document name, the configuration name or any other manually-written value. You can also choose to link the part number to the sub-assemblies or not:



      The question is: how can I get the final value assigned to the parameter "PART NUMBER"? I found this in the API help:


      2016 SOLIDWORKS API Help - Change Configuration Properties Example (VBA)



      Function BOMPartNumber(config As SldWorks.Configuration, document As SldWorks.ModelDoc2) As String

          Select Case config.BOMPartNoSource

          Case SwConst.swBOMPartNumberSource_e.swBOMPartNumber_ConfigurationName

              BOMPartNumber = config.Name

          Case SwConst.swBOMPartNumberSource_e.swBOMPartNumber_DocumentName

              BOMPartNumber = document.GetTitle

          Case SwConst.swBOMPartNumberSource_e.swBOMPartNumber_UserSpecified

              BOMPartNumber = config.AlternateName

          Case SwConst.swBOMPartNumberSource_e.swBOMPartNumber_ParentName

              Dim parentConfig As SldWorks.Configuration

              Set parentConfig = config.GetParent

              If parentConfig.BOMPartNoSource = SwConst.swBOMPartNumberSource_e.swBOMPartNumber_ParentName Then

                  BOMPartNumber = BOMPartNumber(parentConfig, document)


                  BOMPartNumber = parentConfig.Name

              End If

          End Select

      End Function



      Isn't there any more simple way to do the same? Something like a property or method in the "IModelDoc2" object or any other. It's strange that you can't access this property directly, taking into account the importance of that parameter in the production chain.