DXF macro export sheet by sheet

Hello,

Thank you for the feedback, sorry I'm not a forum consumer, I don't know the rules to follow. :sweat_smile:

Below is my macro:

Option Explicit
Dim swApp       As SldWorks.SldWorks
Dim swModel     As SldWorks.ModelDoc2
Dim swDraw      As SldWorks.DrawingDoc
Dim swCustProp  As CustomPropertyManager
Dim valOut1     As String
Dim resolvedValOut1 As String
Dim sPathname   As String
Dim vSheetName  As Variant
Dim nErrors     As Long
Dim nWarnings   As Long
Dim i           As Long
Dim bRet        As Boolean
Dim lParam      As Long

Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    
    lParam = swApp.GetUserPreferenceIntegerValue(swDxfMultiSheetOption)
    
    'Changement paramétrage export dxf si différent de feuille active
    If lParam <> 0 Then
        bRet = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swDxfMultiSheetOption, swDxfMultisheet_e.swDxfActiveSheetOnly)
    End If
    
    ' On récupère la date du jour et on la met dans un format pouvant se mettre dans le nom d'un fichier
    Dim dateNow As String
    dateNow = Replace(Date, "/", ".")
    
    ' On récupère les valeurs qui nous intéresse dans les propriétés personnalisées du plan
    Set swCustProp = swModel.Extension.CustomPropertyManager("")
    swCustProp.Get2 "Révision", valOut1, resolvedValOut1

    sPathname = Replace(swModel.GetPathName, ".SLDDRW", "")
    vSheetName = swDraw.GetSheetNames
    For i = 0 To UBound(vSheetName)
        bRet = swDraw.ActivateSheet(vSheetName(i))
        bRet = swModel.SaveAs4(sPathname & " - " & resolvedValOut1 & " - " & dateNow & "_" & vSheetName(i) & ".dxf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
    Next i
    
    ' Retour à la Feuille 1
    bRet = swDraw.ActivateSheet(vSheetName(0))
    
    ' Remise en place du paramétrage initial
    bRet = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swDxfMultiSheetOption, lParam)
End Sub

In any case, I thank you all very much. :grin:
Manu

Hello;

Overall I don't see too many inconsistencies in the code, to see what more professionals than me say about it :sweat_smile:.
I would have just used a variable for the " Revision " property
Style:

Dim MyRevision as string
then
MyRevision = swCustProp.Get2 "Révision", valOut1, resolvedValOut1

And to add the page number, why not use (i+1)?
This will give:

bRet = swModel.SaveAs4(sPathname & " - " & MyRevision & " - " & dateNow & "_" & vSheetName(i) & i+1 & ".dxf", swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)

Also, I'm not a big fan of using " ." dots in the file name,
So (but it's optional): dateNow = Replace(Date, " / ", " _ ")

And finally, I'll add a check to check that MyRevision isn't " Empty ":

If MyRevision ="" then
 msgbox ("La propriété Révision n’existe pas.")
exit sub
end if

To save a little time, it is possible to disable Solidworks graphical updates during processing:

swModel.FeatureManager.EnableFeatureTree = False 'Désactivation de la mise à  jour treeManager
modView.EnableGraphicsUpdate = False 'Désactivation de la mise à  jour graphique
EnableFeatureTreeWindow = False 'Désactivation de la mise à  jour de la fenetre

But they will have to be reactivated at the end of the treatment:

swModel.FeatureManager.EnableFeatureTree = True 'Activation de la mise à  jour treeManager
modView.EnableGraphicsUpdate = True 'Activation de la mise à  jour graphique
EnableFeatureTreeWindow = True 'Activation de la mise à  jour de la fenetre

Hello,
It all depends on the " heaviness " of each leaf.
It's possible that SW lags at this level (I have a bit the same behavior on some macros that only do a simple PDF export)

At the same time more than 100 sheets, not at all surprised that it lags!

And this reinforces my way of doing things:
1 piece = one file = 1 plan then assembly (except for multi-body tubular welded construction)

OK thank you for your feedback.
I'm trying to modify this and I'm trying my next generation of DXF.

For your information, I am in welded construction for furniture modeling, so depending on the furniture there can be many parts to plan. And I am asked to purify as much of the leaves as possible, so a lot of leaves for one and the same piece.

In any case, I thank you all very much for the time you have given to answer me.