Solidworks CSV Export

Hello

For quite some time, I've had a problem with the .cvs export of my nomenclatures. Let me explain: it seems that, basically, Solidworks uses commas as separators, and I would rather have semicolons. So I have to save in .xls, then with excel, to save in .csv (excel uses the right separators), which adds a tedious step to each export. 

Do you have a solution? I'm not up to speed with macros, do you think I should go through this way? 
I didn't find a solution  after a search.

Thank you!

Hello

Apart from treating it with the windows notepad and the replace function.

Look at this anyway https://www.lynkoa.com/forum/3d/export-nomenclature-solidworks-par-vb

Jerome

2 Likes

I don't know if they are related but don't hesitate to do the test by changing the list separator in the regional options...

Sometimes it's faster =)

 

Hello to you both,

Unfortunately, Macros227's   solution doesn't work:(

As for macros, I don't master them at all. I guess it's not at all complicated to export a table with semicolons as separators, or do I risk spending time on it?

Hello

It shouldn't take you much more than 5 minutes, you take the macro that is in the question of the link given by Todesco and in it you replace the line:

sRowStr = sRowStr & swTable.Text(i, j) & " | "

by it:

sRowStr = sRowStr & swTable.Text(i, j) & "; "

And like that you have to get a CSV file with a; as a separator. This is stored in the same folder as your plan.

Kind regards

3 Likes

Thank you very much, indeed it works!
However, would there be a way to export only the "active" nomenclature? I sometimes have multiple BOMs per page, and I would like to be able to choose which of them is exported. With this, macro, it is the last nomenclature found that is recorded if I understand correctly.

Thanks in advance 

Hello

The macro in question allows you to select all the BOMs in the plan and write them to the csv file (subject to making the modification explained by .PL in the original discussion to avoid each BOM export overwriting the previous BOM export).

If you want to extract only a BOM that you have selected in the tree, this should be possible by replacing the rows:

    Set swFeat = swModel.FirstFeature

    Do While Not swFeat Is Nothing
        If "BomFeat" = swFeat.GetTypeName Then
            Set swBomFeat = swFeat.GetSpecificFeature2
            ProcessBomFeature swBomFeat
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop   
    vTableArr = swBomFeat.GetTableAnnotations

By using the "GetSelectedObject6" function that you can find here. Don't forget to use the "ProcessBomFeature" function after the selection function.

Kind regards

Thank you for the answer. 
I don't know the syntax, but this doesn't work:

  set swFeat = GetSelectedObject6
  Set swBomFeat = swFeat.GetSpecificFeature2
  ProcessBomFeature swBomFeat

Hello

You replace the lines:

   Set swFeat = swModel.FirstFeature
    Do While Not swFeat Is Nothing
        If "BomFeat" = swFeat.GetTypeName Then
            Set swBomFeat = swFeat.GetSpecificFeature2
            ProcessBomFeature swBomFeat
        End If
        Set swFeat = swFeat.GetNextFeature
    Loop
    
    vTableArr = swBomFeat.GetTableAnnotations

By:

    Set SelMgr = swModel.SelectionManager
    Set swBomFeat = SelMgr.GetSelectedObject6(1, 0)
    
    ProcessBomFeature swBomFeat

Kind regards

Thank you very much!

It does work. My mistake was to think that the nomenclature was the one selected in the central interface, and not in the tree on the left of the screen. 
Is there a function to export the "active" nomenclature, in the sense of the word, selected in the central interface?

Yes, it's possible, but by also modifying the BOM export function because suddenly it's no longer a "BomFeature" element that is transmitted:

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
    
Sub main()

    Dim swFeat As SldWorks.Feature
    Dim swBomFeat As SldWorks.BomFeature
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    Set selmgr = swModel.SelectionManager
    Set vTable = selmgr.GetSelectedObject6(1, -1)
    ProcessBomSelect vTable

    MsgBox "Export de la BOM terminé."
End Sub

Sub ProcessBomSelect(vTable As Variant)
    Dim swTable As SldWorks.TableAnnotation
    Dim swAnn As SldWorks.Annotation
    Dim nNumCol As Long
    Dim nNumRow As Long
    Dim sRowStr As String
    Dim I As Long
    Dim J As Long

    Set swTable = vTable
    Set swAnn = swTable.GetAnnotation

    nNumCol = swTable.ColumnCount
    nNumRow = swTable.RowCount

    Dim xlsPath As String
    xlsPath = Mid(swModel.GetPathName, 1, InStrRev(swModel.GetPathName, "\"))

    Dim xlsName As String
    If InStrRev(swModel.GetTitle, ".") > 0 Then
        xlsName = Mid(swModel.GetTitle, 1, InStrRev(swModel.GetTitle, ".") - 1) & ".csv"
    Else
        xlsName = swModel.GetTitle & ".csv"
    End If

    For I = 0 To nNumRow - 1
        sRowStr = ""
        For J = 0 To nNumCol - 1
            sRowStr = sRowStr & swTable.Text(I, J) & ";"
        Next J
    Next I

    swTable.SaveAsText xlsPath & xlsName, ";"
End Sub

Kind regards

It's really excellent and exactly what I wanted, thank you for your precious help!