Hello
When you generate a DXF or DWG of a plan that has more than one sheet, SW generates one file per sheet (set like this) except that it names them with the sheet number as a prefix:
For example, if the 3-sheet file "DEAL-D1.slddrw", the DXFs will be:
- 00_ DEAL-D1_C.dxf
- 01_AFFAIRE-D1_C.dxf
- 02_AFFAIRE-D1_C.dxf
I would have preferred to have
- DEAL-D1_C - 01.dxf or DEAL-D1_C - Sheet1.dxf
- DEAL-D1_C - 02.dxf or DEAL-D1_C – Sheet2.dxf
- DEAL-D1_C - 03.dxf or DEAL-D1_C – Sheet3.dxf
Do you have an idea because as a beginner in macros, I made one that generates, from a Draw, a ZIP file containing the PDF+DXF of the Draw (all the sheets) + STEP+PDF3D of the planed model.
Example:
"AFFAIRE-Pièce8.sldprt" having 2 configurations, the 1stof which at index B is drawn in the draw "AFFAIRE-D1.slddrw" which is at index C, will give a zip with:
- ZIP File Name: AFFAIRE-D1_C.zip
Content:
- AFFAIRE-D1_C.pdf
- 00_AFFAIRE-D1_C.dxf
- 01_AFFAIRE-D1_C.dxf
- DEAL-Pièce8.1_B.step
- CASE-Pièce8.1_B(PDF3D).pdf
Thank you for your help.
Hello
You should find everything you want (and even more) in the macro shared here.
Kind regards
3 Likes
Thank you very much
I was indeed able to find an answer with your example but also this one:
https://forum.solidworks.com/thread/75412#comment-397610
by combining the files offered in V2.1 and V2.2
In the end, I didn't have to use the function of exporting all the sheets in separate files but to process each sheet in a single file and export it by defining its name according to my conditions. The part I was missing was:
'DXF export manually to have the correct DXF filename and not the system naming 00_, 01_, ...
'Set the DXF export option to export active sheet only
swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDxfMultiSheetOption, swDxfMultisheet_e.swDxfActiveSheetOnly
sFilePath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))
Dim swView As SldWorks.View
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
vSheetName = swDraw.GetSheetNames
For i = 0 TB UBound(vSheetName)
bRet = swDraw.ActivateSheet(vSheetName(i))
' Setting File Names
FinalFileName_dxf = Strings.Left(swfilename, Len(swfilename) - 7) & DrawSepInd & DrawIndRev & " - " & vSheetName(i) & ".dxf"
If Verification(FinalFileName_dxf) = True Then
PopupOverwriteFile = MsgBox ("A DXF file of the same name already exists, do you want to replace it?" & vbNewLine & vbNewLine & FinalFileName_dxf, vbYesNoCancel)
If PopupOverwriteFile = vbNo Then
'Do nothing
Else
If PopupOverwrite File = vbYes Then
bRet = swDraw.SaveAs4(FinalFileName_dxf, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
Else
If PopupOverwriteFile = vbCancel Then
Exit Sub
End If
End If
End If
Else
bRet = swDraw.SaveAs4(FinalFileName_dxf, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
End If
Next i
' Switch back to first sheet
bRet = swDraw.ActivateSheet(vSheetName(0))
Thank you!