AnsweredAssumed Answered

DXF macro not working corectly in SW2020 SP0.0 anymore

Question asked by Wojciech Pogorzelski on Oct 21, 2019
Latest reply on Oct 29, 2019 by Jeremy Jacobs

I have been using this DXF export macro for a while and it worked like a charm for me till SW2019.

I have noticed that there is some geometry details missing in a exported dxf file while running this macro in Sw2020.

Unfortunately I have no idea what have changed in SW2020 and how to fix it.

Could anyone help me fix it?

 

First screen shows a result of macro run under SW2020 - some holes are missing:

dxf - macro export

Second screen shows manual save as dxf file - geometry is complete

And here is a macro code:

'---------------------------------------------------------------------------
' Preconditions:
' - Sheet metal part is open.

' Postconditions:
' - Creates DXF file from Sheet metal part for subsequent import into laser cutting software,
' which requires only the outline and inline of the geometry to be cut without bend lines.
' - Saves dxf file in part folder location.
' - Saves dxf file with the same name as part file.
' - Opens dialog box to confirm operation.
' - Opens preview with a defaut system dxf viewer/program or specyfied DXF Viewer.
'--------------------------------------------------------------------------
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swDraw As SldWorks.DrawingDoc
Dim sModelName As String
Dim sPathName As String
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
Dim varViews As Variant
Dim dataViews(1) As String
Dim options As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

'-----------------------------------------------------------------
If swModel Is Nothing Then
swApp.SendMsgToUser2 " Sheet Metal => DXF" & vbNewLine & "" & vbNewLine & " Open file!", swMbWarning, swMbOk
Exit Sub
End If

'-----------------------------------------------------------------
If (swModel.GetType <> swDocPART) Or (swModel.GetBendState = swSMBendStateNone) Then
swApp.SendMsgToUser2 " Sheet Metal => DXF" & vbNewLine & "" & vbNewLine & " Open sheetmetal file!", swMbWarning, swMbOk
Exit Sub
End If

'-----------------------------------------------------------------
sModelName = swModel.GetPathName
sPathName = swModel.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 6)
sPathName = sPathName + "dxf"

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

dataViews(0) = "*Current"
dataViews(1) = "*Front"

varViews = dataViews

'dxf export
options = 1
swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportSheetMetal, True, varAlignment, False, False, options, Null

'-----------------------------------------------------------------
swModel.ShowNamedView2 "*Izometryczny", 7
swModel.ViewZoomtofit2
swModel.Save
'-----------------------------------------------------------------
Shell "C:\Program Files\SOLIDWORKS Corp\eDrawings\eDrawings.exe """ & sPathName & "", vbNormalFocus

End Sub

Outcomes