API/VBA: control of a BOM BOM table

Hello

Is there a way to tell a nomenclature table to which configuration it is attached?

I already have the config in a variable."vNameConf"

I tried: 


Dim swBomTable As SldWorks.BomTableAnnotation or Dim swBomTable As SldWorks.IBomTable

' table of nomenclature
            boolstatus = Part.Extension.SelectByID2("Nomenclature2", "DRAWINGVIEW", 0.195997909234212, 0.164382166839605, 0, False, 0, Nothing, 0)
            Set swBomTable = swSelMgr.GetSelectedObject6(1, 0)
            swBomTable.ReferencedConfiguration = vNameConf(i)

 

Kind regards

Hello

Try the SetConfigurations method 

Example1 Example2

1 Like

Thank you Jerome,

Not easy with their example, which sometimes translates halfway.

I tried to code this:

  
    BomFeature 
    GetConfigurations (false, visible)
    Visible (0) = True
    SetConfigurations (True, Visible, vNameConf(i))

 

but I don't understand much

In my logic you have to identify the array and then assign the config to it

 

Dim swBomFeat As SldWorks.BomFeature
 

 swBomFeat ="Nomenclature2"
boolstatus = swBomFeat. SetConfigurations (True, Visible, vNameConf(i))

Too bad it's not that simple.

The rest of all on time 

Replaces "test" with the name of the configuration to be used

Option Explicit
Sub main()

    Call NomenclatureConfig("test")

End Sub
Sub NomenclatureConfig(ByVal ConfigName As String)
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swView As SldWorks.View
    Dim swTableAnn As SldWorks.TableAnnotation
    Dim swBomFeat As SldWorks.BomFeature
    Dim vTables As Variant
    Dim vTable As Variant
    Dim ConfigNames As Variant
    Dim ConfigVis As Variant
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swView = swDraw.GetFirstView
    If swView.GetTableAnnotationCount > 0 Then
        vTables = swView.GetTableAnnotations
        For Each vTable In vTables
            Set swTableAnn = vTable
            If swTableAnn.Type = swTableAnnotationType_e.swTableAnnotation_BillOfMaterials Then
                Set swBomFeat = swTableAnn.BomFeature
                ConfigNames = swBomFeat.GetConfigurations(False, ConfigVis)
                For i = 0 To UBound(ConfigNames)
                    'Debug.Print "configuration indice: " & i & ", Nom: " & ConfigNames(i) & ", Visible: " & ConfigVis(i) '
                    If ConfigNames(i) = ConfigName Then
                        ConfigVis(i) = True
                    Else
                        ConfigVis(i) = False
                    End If
                Next
                swBomFeat.SetConfigurations False, ConfigVis, ConfigNames
            End If
        Next
    End If
    swDraw.ClearSelection2 True
End Sub

 

1 Like

Hello Jerome,

Thank you for your time.

I used this code but it doesn't get anything on the plan.

 I've been on it since 7 a.m. but there are a lot of variables.

 For a novice like me without the annotations ' I struggle.

See you soon

 

 

What does it write in the immediate window if you activate the line:

Debug.Print "configuration index....

Can you attach a test file. Thank you

Jerome

Thank you for this new info. I didn't understand the usefulness of this line and the cost of the execution window. I started only a month ago

Here is the result:

- Hint Configuration: 0, Name: Default, Visible: False
- Hint Configuration: 1, Name: ODCA1001, Visible: True
- Index: 2, Name: ODCA1001SP, Visible: False
- Hint Configuration: 3, Name: ODCA1001VR, Visible: False
- Index: 4, Name: ODCA1001VRSP, Visible: False
- Configure Index: 5, Name: ODCA1002, Visible: False
- Hint Configuration: 6, Name: ODCA2001, Visible: False
- Hint Configuration: 7, Name: ODCA2002, Visible: False

the table is not modified it remains in its original config

Kind regards

Oops

I have just realized that it is my request that is not clear.

I have a nomenclature table on a plan with a given configuration, and I want to tell it to use another one (configuration).

Kind regards

Hello,

 If I change 

Call NomenclatureConfig("odca1001SP")

The result is the same

- Hint Configuration: 0, Name: Default, Visible: False
- Hint Configuration: 1, Name: ODCA1001, Visible: True
- Index: 2, Name: ODCA1001SP, Visible: False
- Hint Configuration: 3, Name: ODCA1001VR, Visible: False
- Index: 4, Name: ODCA1001VRSP, Visible: False
- Configure Index: 5, Name: ODCA1002, Visible: False
- Hint Configuration: 6, Name: ODCA2001, Visible: False
- Hint Configuration: 7, Name: ODCA2002, Visible: False

 

Jerome

I find this S weird but if I remove it it doesn't change anything (the one underlined)

swBomFeat.SetConfigurations False, ConfigVis, ConfigNames

Kind regards

Jerome

The hot laundry answers me on a Macro of my own

The configuration changes at the bom feature:

    Set swBomFeat = swBomAnn.BomFeature

    swBomFeat.Configuration = "ODCA1001"

I tried to use this line in my code without result.

 

Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim swSheet As SldWorks.Sheet
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Dim vNameConf As Variant

' V BOM
Dim swBomAnn As BomTableAnnotation
Dim swBomFeat As SldWorks.BomFeature

Sub main()
    
    ' bibliothec SW
    Set swApp = Application.SldWorks
    ' model actif de SW
    Set swModel = swApp.ActiveDoc
    ' selection de ce model
    Set swSelMgr = swModel.SelectionManager
    'mémorisé l'objet6(1,0)?
    Set swBomAnn = swSelMgr.GetSelectedObject6(1, 0)
    ' On affect la config
    vNameConf = "ODCA1001"
    
    'La configuration se change au niveau de la bom feature :

    Set swBomFeat = swBomAnn.BomFeature

    swBomFeat.Configuration = vNameConf
    
End Sub

 


table1.swp

Try this:

Option Explicit
Sub main()

    Call NomenclatureConfig("ODCA1001SP")

End Sub
Sub NomenclatureConfig(ByVal ConfigName As String)
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swView As SldWorks.View
    Dim swTableAnn As SldWorks.TableAnnotation
    Dim swBomFeat As SldWorks.BomFeature
    Dim vTables As Variant
    Dim vTable As Variant
    Dim ConfigNames As Variant
    Dim ConfigVis As Variant
    Dim i As Integer
    Debug.Print "Configuration à activée: " & ConfigName
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swView = swDraw.GetFirstView
    If swView.GetTableAnnotationCount > 0 Then
        vTables = swView.GetTableAnnotations
        For Each vTable In vTables
            Set swTableAnn = vTable
            If swTableAnn.Type = swTableAnnotationType_e.swTableAnnotation_BillOfMaterials Then
                Set swBomFeat = swTableAnn.BomFeature
                ConfigNames = swBomFeat.GetConfigurations(False, ConfigVis)
                For i = 0 To UBound(ConfigNames)
                    Debug.Print "configuration indice: " & i & ", Nom: " & ConfigNames(i) & ", Visible: " & ConfigVis(i) '
                    If LCase(ConfigNames(i)) = LCase(ConfigName) Then
                        ConfigVis(i) = True
                        Debug.Print "Configuration activé: " & ConfigNames(i)
                    Else
                        ConfigVis(i) = False
                    End If
                Next
                swBomFeat.SetConfigurations False, ConfigVis, ConfigNames
            End If
        Next
    End If
    swDraw.ClearSelection2 True
End Sub

 

1 Like

Hello Jérôme,

Thank you

I doubt to help you one day given your level and your field of activity, but know your never, my strong point is the left shapes (design, surface)

Thank you again,

Kind regards

 

1 Like