How to retrieve the displayed Part Number value ... in a bill of materials

Hi all

In an assembly, I try to retrieve the "Part number displayed when used in a BOM:" value of the component I selected. I already get the name of the configuration of the selected component with the code below but I dry a little for the part number displayed in the nomenclature. Does anyone have the solution?

Dim swApp As SldWorks.SldWorks
Sun swSelMgr As SldWorks.selectionMgr
Dim swModel As SldWorks.ModelDoc
Dim ConfigMgr As ConfigurationManager
Dim Component As SldWorks.Component2

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set ConfigMgr = swModel.ConfigurationManager
    
    'Select component
    Debug.Print "Selection Type  = " & swSelMgr.GetSelectedObjectType2(1)
    Set Component = swSelMgr.GetSelectedObjectsComponent4(1, -1)

    ' Show Config1 and make it the active configuration
    Debug.Print "ConfigName SelectedComponent =" & Component.ReferencedConfiguration
    Debug.Print "ConfigName SelectedComponent = " & ConfigMgr.ActiveConfiguration.UseAlternateNameInBOM
    

End Sub

If this is the part number create via balloons in a BOM as part registration

I think (I'm sure) that this is not possible

If this number is created via the customize property of the part so its part ref

there it's possible

Hello

In the API Help, search for: Get Components in Each BOM Table Row Example (VBA)

Normally it meets the need, then you have to adapt.

1 Like

Thank you for your answers.

I found the solution with GetConfigurationParams.

Example:

Dim ActiveConfig                As String
Dim bRet                        As Boolean
Dim ConfigMgr                   As ConfigurationManager
Dim Component                   As SldWorks.Component2
Dim ParamConfigValue            as Variant
Dim swApp                       As SldWorks.SldWorks
Sun swSelMgr                    As SldWorks.selectionMgr
Dim swModel                     As SldWorks.ModelDoc

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set ConfigMgr = swModel.ConfigurationManager
    
' Active Configuration ID and Name Recovery
    'IDconfig = swModel.ConfigurationManager.ActiveConfiguration.GetID
    ActiveConfig = swModel.ConfigurationManager.ActiveConfiguration.Name
    bRet = ConfigMgr.GetConfigurationParams(ActiveConfig, "PART $NUMERO", ParamConfigValue)
    'Debug.Print' Config ID enabled on opening: " & IDconfig
    Debug.Print "Config name active on opening: " & ActiveConfig
    Debug.Print "Number used in BOMs: " & ParamConfigValue(1)      'ParamConfigValue 1 matches Part Number used in BOM

End Sub

Thank you for your answers.

I found the solution with GetConfigurationParams.

Example:

Dim ActiveConfig                As String
Dim bRet                        As Boolean
Dim ConfigMgr                   As ConfigurationManager
Dim Component                   As SldWorks.Component2
Dim ParamConfigValue            as Variant
Dim swApp                       As SldWorks.SldWorks
Sun swSelMgr                    As SldWorks.selectionMgr
Dim swModel                     As SldWorks.ModelDoc

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set ConfigMgr = swModel.ConfigurationManager
    
' Active Configuration ID and Name Recovery
    'IDconfig = swModel.ConfigurationManager.ActiveConfiguration.GetID
    ActiveConfig = swModel.ConfigurationManager.ActiveConfiguration.Name
    bRet = ConfigMgr.GetConfigurationParams(ActiveConfig, "PART $NUMERO", ParamConfigValue)
    'Debug.Print' Config ID enabled on opening: " & IDconfig
    Debug.Print "Config name active on opening: " & ActiveConfig
    Debug.Print "Number used in BOMs: " & ParamConfigValue(1)      'ParamConfigValue 1 matches Part Number used in BOM

End Sub