API to store attributes

Hello
Starting from an assembly, I want to store the attributes of the parts and assemblies in an array so that I can do various quality control processes on it.

I know the max number of columns in my nomenclature (nb of attribut ~12), but I don't know the number of rows at the beginning. I can have bills of materials of more than 300 lines.

Knowing that you have to define the dimensions of the board at the beginning, what would be the best method for you (speed, stability, etc.)?

I thought of scanning all the nomenclature to know the number of rows, then define the size of the table (is it possible?) ... Maybe there are better methods?

Thank you.

A+

Hello;

If I understand correctly, you want to accumulate all your BOMs from an assembly in Excel ... A Save Under of the detailed BOM of your main assembly will have to do the trick.
And why do you need to know the Number of Lines... it doesn't seem necessary to me, if you have several BOMs (I don't see why) it's easy, in excel, to "paste" a quantity of data on "The next empty line":

The VBA (excel) commands to get the coordinates from the next blank line are: (For example):

'Retourne sur " derligne " le numéro de la prochaine ligne non vide (CTRL+ flèche bas)
derligne = Range("C1").End(xlDown).Row


derligne = Sheets("DATA").Range("E1048576").End(xlUp).Row
'Retourne sur " derligne " le numéro de DERNIERE ligne non vide


'Compte le nombre de lignes jusqu’à la dernière vide de la colonne
derligne = range("A" & rows.count).end(xlup).row


Kind regards.

2 Likes

Hello

Thank you for taking the time to answer me.

No, I work in a main assembly with sub-assemblies and parts, with a single nomenclature of the "tabbed list" type, or a macro that crosses the assemblies.

So I want to store the attributes in a 2-dimensional table, so that I can then intervene directly on the parts in SW without going through Excel.

A+

Hello

So outside of Excel, in VBA, it is not possible to dynamically change the size of a multidimensional table.

So you need to know its size from the beginning by scanning the number of rows and then applying the value found to the array variable.

Otherwise you have to play with two one-dimensional array variables and synchronize the filling of them.

1 Like

Hello;

If you want to have the Number of Columns and the Number of Rows,

nNumCol = swTable.ColumnCount
nNumRow = swTable.RowCount

    Dim swView As SldWorks.View
    Dim swTable As SldWorks.TableAnnotation
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView

    Do While Not swView Is Nothing
        ' Show the name of the view
        '        Debug.Print "  " & swView.Name

        ' Get the first table annotation for this view
        Set swTable = swView.GetFirstTableAnnotation
        Do While Not swTable Is Nothing
            ProcessTable swApp, swModel, swTable
            ' Get next table annotation for this view
            Set swTable = swTable.GetNext
        Loop
        ' Get the next view
        Set swView = swView.GetNextView
    Loop

Set swAnn = swTable.GetAnnotation
    nNumCol = swTable.ColumnCount
    nNumRow = swTable.RowCount

Kind regards.