VBA Macro to Change Plane BOM

Hello

In a macro, I would like to modify several elements of a plan nomenclature.

1-) The symmetrical configurationDefault or configuration referenced in the plan ->Ok

Code found: https://www.codestack.net/solidworks-api/document/drawing/bom-tables-update-referenced-configuration/

! [](upload://ukhwxSXVFt6vjiJ1XNKMqV6Q7N3.png)

2-) The column width after changing the configuration for the quantity column (this width changes due to a bug)

! [](upload://eg2sXRpMa4geUFZmvlT0m2BHKNs.png)

3- )Change the font size of this same column to 16 instead of 11 because of the previous bug.

For point 1 I should get away with it thanks to the code found, if anyone has any leads for points 2 and 3.

 

Thank you

For point 2 also found:

Dim swApp As Object
Sub main()
  Dim swModel As ModelDoc2
  Dim swdraw As DrawingDoc
  Dim tab1 As TableAnnotation
 
   
  Set swApp = Application.SldWorks
  Set swModel = swApp.ActiveDoc
  Set swdraw = swModel
 
  Set tab1 = swdraw.SelectionManager.GetSelectedObject6(1, 0)
  SetColumnWith tab1
 
End Sub



Sub SetColumnWith(swTable As TableAnnotation)
        Dim index As Integer
        Dim swAnnotation As Annotation
        Dim swDislplayData As DisplayData
        'Dim TextWidth As Double

       
        Set swAnnotation = swTable.GetAnnotation
        Set swDislplayData = swAnnotation.GetDisplayData

        For i = 0 To swTable.ColumnCount - 1
        Dim ColumnWidth As Double
        ColumnWidth = swTable.GetColumnWidth(i)
        
        Debug.Print i & ":" & ColumnWidth * 1000
        If i = 1 Then
            'bRet = swTable.SetColumnWidth (i)
            Dim ColWd As Double
            ColWd = swTable.GetColumnWidth(i)
            Debug.Print ColWd
            retHt = swTable.SetColumnWidth(i, 0.0135, 0)
        End If
        Next
    End Sub

This modifies my column well or I have the problem of width and different font.

There is only point 3-) left to change this font.

Option 1 modify it in the nomenclature by changing the font of the column (no idea how to do this

or option 2 change the option in tool option/Document Properties/Tables/Nomenclature/Font

If anyone has a solution to achieve one of these 2 possible options.

Thank you

Hello sbadenis
In theory, your Drawing Document should already have the appropriate settings (Drawing Template)....

Have you tried "SetTextFormat"? (Solidworks Help: SetTextFormat Method)
With:     value = instance. SetTextFormat(UseDoc, TextFormat)

UseDoc
True to use the document setting, false to not
TextFormat
ITextFormat object
Kind regards
1 Like

Thanks @Maclane for the lead. In the end, as the problem comes from my document template where the font is set to 16 instead of 10, I preferred to make the modification at the document level, even if your solution probably worked too, but seemed less logical to me for my needs.

For those who would be interested, here is the solution chosen:

Dim swDraw As DrawingDoc
Dim swAnnotation As Annotation
Dim UserPref As Integer
Dim UserPrefOption As Integer
Dim swTextFormat As SldWorks.TextFormat
Dim bRet As Boolean

        Set swTextFormat = swAnnotation.GetTextFormat(1)
            swTextFormat.CharHeightInPts = "10"
            swTextFormat.TypeFaceName = "Arial"
            swTextFormat.Bold = False
            swTextFormat.Italic = False

        bRet = swDraw.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingBillOfMaterialTextFormat, swDetailingBillOfMaterial, swTextFormat)

 

 

1 Like