Comment peut on exporter une nomenclature vers Excel en vba, car je travail mes débit matière sur Excel que j'exporte vers un logiciel de débit.
Mais je voudrais exporter la nomenclature vers un fichier excel ou un csv ce qui me permettrais d'importer directement ma nomenclature vers mon logiciel de débit.
Ou alors encore mieux de récupéré les infos de la nomenclature sans forcément la créer, c'est a dire désignation, longueur, largeur, épaisseur, nombre plus une ou deux propriété d'un formulaire, pour l'importer dans Excel
Ce poste fait suite à l'épisode 1 saison 1 que voici. https://www.lynkoa.com/forum/solidworks/ins%C3%A9rer-mise-en-plan-avec-nomenclature-solidworks
Regardez surtout les derniers posts il s'agit de créer une fonction automatique que n'offre pas SW à ce jour, apparemment. L'idéal Pour @treza88serait de générer directement le fichier excel sans créer la nomenclature ni dans l'ASM ni dans la MEP qu'il n'utilise pas à ce stade.
Synthèse lançer un bout de logiciel qui va générer une nomenclature dans excel sans que cela n'apparaisse dans l'ASM ni dans la MEP. ;-) ;-)
Bonjour, Il y a plusieurs façons d'exporter la nomenclature par macros. Pour le dessin d'un assemblage de pièces:
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
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
J'ai trouvé un bout de code qui fonctionne pour créer la table [ swtable = swDrawing.InsertTableAnnotation2(False, 0, 0, swBOMConfigurationAnchor_TopLeft, Templatetable, 4, 2)]
par contre dans mon fichier excel créé cela récupère la formule de la propriété [$PRP:"SW-Nom de fichier(File Name)"[ mais pas la valeur alors que sur la table sur SW est correct (voir imprim ecran) et je n'arrive pas a modifier le code pour supprimer la table général créé.
Merci pour votre aide.
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