SolidWorks Macro to Preview DXF file before Saving.
I have this macro that saves a Sheetmetal into a DXF file in a specified location. I am trying to add some line to the code to preview the file before saving. Because right now, the file is saved in the desired location but I will have to open the saved file to review it. I am new to VBA.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim FilePath As String
Dim FileName As String
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
Dim varViews As Variant
Dim dataViews(1) As String
Dim options As Long
Dim sPathName As String
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Check if there is any active document If swModel Is Nothing Then MsgBox "1: Please open a Sheet Metal Part" Exit Sub End If
' Check the active document is a Part If swModel.GetType <> swDocPART Then MsgBox "2: Please open a Sheet Metal Part" Exit Sub End If
' Check the active document is a Sheet Metal Part If swModel.GetBendState = 0 Then MsgBox "3: Please open a Sheet Metal Part" Exit Sub End If
' Get Path sPathName = swModel.GetPathName sPathName = Left(sPathName, InStrRev(sPathName, "\SWX")) sPathName = sPathName & "DXF"
'Get File Name FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "") + 1) FileName = Left(FileName, InStrRev(FileName, ".") - 1) FilePath = sPathName & FileName & ".DXF" ' Change DXF to DWG if DWG file is needed
'Export Flat Pattern Set swPart = swModel
dataAlignment(0) = 0#
dataAlignment(1) = 0#
dataAlignment(2) = 0#
dataAlignment(3) = 0#
dataAlignment(4) = 0#
dataAlignment(5) = 0#
dataAlignment(6) = 0#
dataAlignment(7) = 0#
dataAlignment(8) = 0#
dataAlignment(9) = 0#
dataAlignment(10) = 0#
dataAlignment(11) = 0#
varAlignment = dataAlignment
options = 5 '0000101 - include flat-pattern geometry, bend lines and sketches
swPart.ExportToDWG2 FilePath, swModel.GetPathName, swExportToDWG_ExportSheetMetal, True, varAlignment, False, False, options, Null
End Sub