Eksport VBA BOM SolidWorks do programu Excel

Witam wszystkich,

Jak możemy wyeksportować zestawienie materiałów do Excela w vba, ponieważ pracuję nad przepływem materiałów w Excelu , który eksportuję do oprogramowania przepływowego.

Chciałbym jednak wyeksportować zestawienie materiałów do pliku Excel lub csv, co pozwoliłoby mi zaimportować zestawienie materiałów bezpośrednio do mojego oprogramowania przepływowego.

Albo jeszcze lepiej pobrać informacje z nomenklatury bez konieczności jej tworzenia, tj. oznaczenie, długość, szerokość, grubość, liczbę oraz jedną lub dwie właściwości formularza, aby zaimportować je do Excela

Z góry dziękuję

Nie ma nikogo do rady w moim pytaniu, ale może nie jestem jasny w mojej prośbie?

Nie wahaj się zapytać mnie, czy nie wyraziłem się jasno.

Witam @ wszystkich

Ten post następuje po odcinku 1 sezonu 1 poniżej.
https://www.lynkoa.com/forum/solidworks/ins%C3%A9rer-mise-en-plan-avec-nomenclature-solidworks

Spójrz szczególnie na najnowsze posty, chodzi o stworzenie automatycznej funkcji, której SW najwyraźniej do tej pory nie oferuje. Idealnym rozwiązaniem dla @treza88 byłoby wygenerowanie pliku Excel bezpośrednio, bez tworzenia nomenklatury ani w ASM, ani  w MEP, której nie używa na tym etapie.

Uruchom  oprogramowanie, które wygeneruje zestawienie materiałów w Excelu bez pojawiania się w ASM lub w MEP.   ;-) ;-) 

Pozdrowienia

1 polubienie

Witam
Istnieje kilka sposobów eksportowania zestawienia komponentów za pomocą makr.
 W przypadku rysunku zespołu części:

Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swActiveView As SldWorks.View
    Dim swBOMTable As SldWorks.BomTableAnnotation
    Dim Config As String
    Dim TemplateName As String

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swActiveView = swDraw.GetFirstView
    Set swActiveView = swActiveView.GetNextView
    Config = swActiveView.ReferencedConfiguration
    TemplateName = "C:\Program Files\SolidWorks Corp\SolidWorks\lang\english\bom-standard.sldbomtbt"

    Set swBOMTable = swActiveView.InsertBomTable2(False, 0, 0.2, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, swBomType_e.swBomType_Indented, Config, TemplateName)
    WriteBom "C:\Temp\myBom.xls", swBOMTable
    
    ' delete table
    Dim swBOMFeat As SldWorks.BomFeature
    Set swBOMFeat = swBOMTable.BomFeature
    Dim swFeat As SldWorks.Feature
    Set swFeat = swBOMFeat.GetFeature
    swFeat.Select2 False, -1
    swModel.EditDelete
    
End Sub

Sub WriteBom(FilePath As String, table As SldWorks.TableAnnotation)
    Dim N As Integer
    N = FreeFile
    Open FilePath For Output As #N
    Dim i As Integer
    Dim j As Integer
    Dim myArray() As Variant
    ReDim myArray(table.ColumnCount - 1)
    For i = 0 To table.RowCount - 1
        For j = 0 To table.ColumnCount - 1
            myArray(j) = table.Text(i, j)
        Next
        Print #N, Join(myArray, vbTab)
    Next
    Close #N
End Sub

 

2 polubienia

W przypadku rysunku listy elementów ciętych:

Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swActiveView As SldWorks.View
    Dim swWeldTable As SldWorks.WeldmentCutListAnnotation
    Dim Config As String
    Dim TemplateName As String

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swActiveView = swDraw.GetFirstView
    Set swActiveView = swActiveView.GetNextView
    Config = swActiveView.ReferencedConfiguration
    TemplateName = "C:\Program Files\SolidWorks Corp\SolidWorks\lang\english\cut list.sldwldtbt"

    Set swWeldTable = swActiveView.InsertWeldmentTable(False, 0, 0.2, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, Config, TemplateName)
    WriteBom "C:\Temp\myBom.xls", swWeldTable
    
    ' delete table
    Dim swWeldFeat As SldWorks.WeldmentCutListFeature
    Set swWeldFeat = swWeldTable.WeldmentCutListFeature
    Dim swFeat As SldWorks.Feature
    Set swFeat = swWeldFeat.GetFeature
    swFeat.Select2 False, -1
    swModel.EditDelete    
End Sub

Sub WriteBom(FilePath As String, table As SldWorks.TableAnnotation)
    Dim N As Integer
    N = FreeFile
    Open FilePath For Output As #N
    Dim i As Integer
    Dim j As Integer
    Dim myArray() As Variant
    ReDim myArray(table.ColumnCount - 1)
    For i = 0 To table.RowCount - 1
        For j = 0 To table.ColumnCount - 1
            myArray(j) = table.Text(i, j)
        Next
        Print #N, Join(myArray, vbTab)
    Next
    Close #N
End Sub

 

2 polubienia

Witam

Jak to zrobić dla stołu ogólnego?

Znalazłem fragment kodu , który działa w celu utworzenia tabeli [ swtable = swDrawing.InsertTableAnnotation2(False, 0, 0, swBOMConfigurationAnchor_TopLeft, Templatetable, 4, 2)]   

z drugiej strony w moim utworzonym pliku Excel pobiera formułę właściwości [$PRP:"Nazwa pliku SW"[ ale nie wartość, podczas gdy w tabeli w oprogramowaniu jest poprawna (patrz druk, ekran)  i nie mogę zmodyfikować kodu, aby usunąć utworzoną tabelę ogólną.

Dziękuję za pomoc.

Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim swActiveView As SldWorks.View
    Dim swWeldTable As SldWorks.WeldmentCutListAnnotation
    Dim Config As String
    Dim TemplateName As String

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swActiveView = swDraw.GetFirstView
    Set swActiveView = swActiveView.GetNextView
    Config = swActiveView.ReferencedConfiguration
    Templatetable = "C:\test article.sldtbt"

Set swTable = swDrawing.InsertTableAnnotation2(False, 0, 0, swBOMConfigurationAnchor_TopLeft, Templatetable, 4, 2)

    WriteBom "C:\Temp\mytable.xls", swTable
    
    ' delete table
    Dim swWeldFeat As SldWorks.WeldmentCutListFeature
    Set swWeldFeat = swWeldTable.WeldmentCutListFeature
    Dim swFeat As SldWorks.Feature
    Set swFeat = swWeldFeat.GetFeature
    swFeat.Select2 False, -1
    swModel.EditDelete    
End Sub

Sub WriteBom(FilePath As String, table As SldWorks.TableAnnotation)
    Dim N As Integer
    N = FreeFile
    Open FilePath For Output As #N
    Dim i As Integer
    Dim j As Integer
    Dim myArray() As Variant
    ReDim myArray(table.ColumnCount - 1)
    For i = 0 To table.RowCount - 1
        For j = 0 To table.ColumnCount - 1
            myArray(j) = table.Text(i, j)
        Next
        Print #N, Join(myArray, vbTab)
    Next
    Close #N
End Sub

 

 

 


imprim_table_generale.png