DXF macro export sheet by sheet

I don't know anything about macros and I'd like to know if it's possible to make a DXF export macro that exports all the sheets of a drawing in separate files keeping the names of the sheets.

After searching on the forum I found this topic with the macro attached, which is what I'm looking for in principle, only it does PDFs and not DXFs:

https://www.lynkoa.com/forum/solidworks/export-diff%C3%A9renci%C3%A9-en-pdf-et-dxf-des-onglets-de-mise-en-plan-par-une-macro

Could a good soul of the forum modify this macro for me to replace the PDF with the DXF.
Will the macro keep the SolidWorks "save as" options that I use when I do it manually, such as using a projection file?

 

Thank you


pdf_page_par_page.swp

Hello

I replaced ".pdf" with ".dxf" in the macro

Try it should work


dxf_page_par_page.swp

Thank you
But it doesn't work properly, 

My drawing has a view with dimensions for the fab ("Sheet 1" tab) and a unfolded sheet metal for laser cutting (tab "Rep A")

The PDF macro does:

a file: "name of the fichier_Feuille 1.PDF"

a "name of the fichier_Rep A.PDF" file

The DXF macro does:

a file:" 00_nom of fichier_Feuille1.dxf"

a file: "00_nom of the A.dxf fichier_Rep"

a file: "01_nom of fichier_Feuille1.dxf"

a file:"01_nom of the A.dxf fichier_Rep"

Hello

I'm not sure I understand the previous message.

Is this the PDF macro done and the DXF macro should do that we need to understand?

I didn't open the macro but if there was simply a change of file extension on the whole code, it logically only saves in another format.

 

That's right

The "pdf_page_par_page.swp" macro creates 1 file per drawing sheet and includes in the PDF file name the name of the drawing file + the name of the sheet

For example, if the drawing file is called "TOTO" and has 2 sheets, "PLAN"  and "Rep A", the PDF macro does:

1 "TOTO_PLAN" file with only the "PLAN" sheet

1 "TOTO_Rep A" file with only the "Rep A" sheet

That's what I'd like to do with DXF.

With the "dxf_page_par_page.swp" macro there are 4 files

"00_TOTO_PLAN" with only the "PLAN" sheet

"00_TOTO_Rep a" with only the "Rep A" sheet

"01_TOTO_PLAN" with only the "PLAN" sheet

"01_TOTO_Rep a" with only the "Rep A" sheet

Hello

With the macro used you need to modify the export options of the dxf/dwg formats in the solidworks options:

Kind regards

Hello

The result is the same, I still have 4 files at the lie of 2

Unlike PDFs

Hello

For my part, I am set to "Export all sheets in a file" and I have no problem.

Only if the setting is "Export all sheets in separate files" the export generates 4 files.

What I have also noticed is that you have to force the change of settings twice for it to be taken into account correctly (probably SW2020 bug).

SW had not taken into account the "Export all sheets to a file" setting

I do have 2 files with the right syntax but it's the same sheet in the 2, the one that is "active" on the screen.

Looking at the macro, there are several times "swExpPdfData" and "SldWorks.ExportPdfData"

and a line  outFile = outFile & IIf(INCLUDE_DRAWING_NAME, drawName & "_", "") & sheetName & ".dxf" or it's ".pdf" in the PDF macro that works

Is it the  ..... ExpPdfData that should be replaced by the equivalent for DXFs?

Oops, I'm looking in more detail, I didn't open the files.

Re

Normally the code below meets the need

Option Explicit
Dim swApp       As SldWorks.SldWorks
Dim swModel     As SldWorks.ModelDoc2
Dim swDraw      As SldWorks.DrawingDoc
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
    
    sPathname = swModel.GetPathName
    sPathname = Left(sPathname, Len(sPathname) - 7)
    vSheetName = swDraw.GetSheetNames
    For i = 0 To UBound(vSheetName)
        bRet = swDraw.ActivateSheet(vSheetName(i))
        bRet = swModel.SaveAs4(sPathname & "_" & 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

 

3 Likes

Thank you
It works perfectly ;-)