Hello; Here is my proposal: -Note: try to publish your code in the message rather than as an attachment, it's more reassuring to "See" a Code rather than Download it. -Note 2: Avoid Accents in VB (Visual Basic) Code at all costs
Dim swApp As Object
Option Explicit
'Enumeration des Option Choisies pour les Exports en DXF (A plat)
' Voir https://help.solidworks.com/2020/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.ipartdoc~exporttodwg2.html
Enum SheetMetalOptions_e
ExportFlatPatternGeometry = 1
IncludeHiddenEdges = 2
ExportBendLines = 4
IncludeSketches = 8
MergeCoplanarFaces = 16
ExportLibraryFeatures = 32
ExportFormingTools = 64
ExportBoundingBox = 2048
End Enum
Sub main()
' Declaration:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim config As SldWorks.Configuration
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
Dim Value_T As String
Dim ResolvedValOut As String
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim wasResolved As Boolean
Dim Error As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
vConfNameArr = swModel.GetConfigurationNames 'Creation de la liste des configurations
For i = 0 To UBound(vConfNameArr) 'Boucle la liste : de l'element 0 jusqu'au nombre d'element dans la liste (Ubound)
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
sConfigName = vConfNameArr(i) 'Recupere l'elementt Numero i de la liste
bShowConfig = swModel.ShowConfiguration2(sConfigName) 'Affiche la configuration
Error = cusPropMgr.Get5("TYPE", True, Value_T, ResolvedValOut, wasResolved) 'Recupere la valeur de la proriete "T" dans la variable "Value_T"
bRebuild = swModel.ForceRebuild3(False) 'Reconstruction du modèle
FilePath = swModel.GetPathName 'Recupere le chemin du fichier SW
PathSize = Strings.Len(FilePath) 'Compte le nombre de caracteres du chemin
PathNoExtension = Strings.Left(FilePath, PathSize - 6) 'Recupere le nom de la piecece en enlevant .Sldrt
NewFilePath = Left(FilePath, InStrRev(FilePath, "\")) & sConfigName & ".DXF" 'Remplace le nom par Type + Lg + Nom de la config (sans Flat pattern).dxf
If False = swModel.ExportToDWG2(NewFilePath, FilePath, swExportToDWG_e.swExportToDWG_ExportSheetMetal, True, Empty, False, False, SheetMetalOptions_e.ExportFlatPatternGeometry + SheetMetalOptions_e.ExportBendLines, Empty) Then
Err.Raise vbError, "", "Failed to export flat pattern"
End If
Next i 'Passe a la prochaine config
bShowConfig = swModel.ShowConfiguration2(vConfNameArr(0)) 'Retour sur la Configuration Principale
End Sub