Set Default BOM Part Number to Document Name

Programming and macros
Post Reply
sjbennett88
Posts: 2
Joined: Tue Feb 18, 2025 12:58 pm
Answers: 0
x 1

Set Default BOM Part Number to Document Name

Post by sjbennett88 »

I have a script that automatically suppresses threaded features and decreases image quality of parts, specifically designed for McMaster components. I am trying to add in functionality that would set the default BOM PN display to show the Document Name rather than Configuration Name. I thought had the language right, but the line I added doesn't seem to do anything (as can be seen by checking the value of swUserPreferenceIntegerValue_e.swDefaultBOMPartNumberForNewConfig before and after that line). What am I doing wrong?

Note - I am not very experienced with the SolidWorks API or programming in general - please be kind

Here is the relevant code. The lines in question are all the way at the bottom:

Code: Select all

Option Explicit

Const APPEND_SELECTION As Boolean = False
Const TYPE_NAME As String = "3DProfileFeature" '3DSketch

Dim swApp As SldWorks.SldWorks

Sub main()

    Set swApp = Application.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Set swModel = swApp.ActiveDoc
    Dim swSelMgr As SldWorks.SelectionMgr
    Set swSelMgr = swModel.SelectionManager
    Dim Part As Object
    Set Part = swApp.ActiveDoc
    Dim bRet As Boolean
    Dim i As Integer
    Dim swFeat As SldWorks.Feature
    
    Dim CurVal As Double
    Dim MaxVal As Double
    Dim MinVal As Double
    Dim NewVal As Double
    
    Dim IntegerSetting As Integer
   
    
    If Not swModel Is Nothing Then
            
        Dim vFeats As Variant
        vFeats = GetAllFeaturesByType(swModel, TYPE_NAME)
        
        swModel.Extension.MultiSelect2 vFeats, False, Nothing
        
        'If swModel.Extension.MultiSelect2(vFeats, False, Nothing) = UBound(vFeats) + 1 Then
            'Err.Raise vbError, "", "Failed to select features"
        'End If
        
        
        For i = 1 To swSelMgr.GetSelectedObjectCount

            Set swFeat = swSelMgr.GetSelectedObject5(i)
            
            If Not swFeat Is Nothing Then

                bRet = swModel.EditSuppress2: 'Debug.Assert bRet

            End If

        Next i
        
    Else
        MsgBox "Please open model"
    End If
    
    'Reduce image quality
    swModel.Extension.GetUserPreferenceDoubleValueRange swImageQualityShadedDeviation, CurVal, MinVal, MaxVal
    NewVal = ((MaxVal - MinVal) * 0.2) + MinVal
    swModel.SetUserPreferenceDoubleValue swImageQualityShadedDeviation, NewVal
    
    'Reduce wireframe quality
    swModel.SetUserPreferenceIntegerValue swImageQualityWireframeValue, 15
    
    'Debug.Print swModel.swBOMPartNumberSource_e.swBOMPartNumber_ConfigurationName
    
    'Set default BOM PN to Document Name - doesn't work yet
    swModel.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDefaultBOMPartNumberForNewConfig, swBOMPartNumberSource_e.swBOMPartNumber_DocumentName 'swBOMPartNumberSource_e.swBOMPartNumber_DocumentName
    
    IntegerSetting = swModel.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swDefaultBOMPartNumberForNewConfig)
    'Debug.Print IntegerSetting
    
End Sub
by Stefan Sterk » Wed Feb 19, 2025 10:00 am
Hi Sjbennett88, Have you seen the macro in the link below?
https://www.codestack.net/solidworks-ap ... m-options/
Go to full post
User avatar
Stefan Sterk
Posts: 47
Joined: Tue Aug 10, 2021 2:40 am
Answers: 5
x 73
x 88

Re: Set Default BOM Part Number to Document Name

Post by Stefan Sterk »

Hi Sjbennett88, Have you seen the macro in the link below?
https://www.codestack.net/solidworks-ap ... m-options/
sjbennett88
Posts: 2
Joined: Tue Feb 18, 2025 12:58 pm
Answers: 0
x 1

Re: Set Default BOM Part Number to Document Name

Post by sjbennett88 »

That was exactly what I needed. Thank you!
Post Reply