I don't know what I'm doing wrong in this macro, but it does export a dwg but also crashes solidworks.
I was trying to replicate a problem with a larger macro that needs to be run twice to export the flat pattern of sheetmetal (first exports a empty dwg and in the second run export the flatpattern)
'Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim varAlignment As Variant Dim dataAlignment(11) As Double Sub main() Set swApp = Application.SldWorks 'Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc If swModel Is Nothing Then swApp.SendMsgToUser2 "A part needs to be open", swMbWarning, swMbOk Exit Sub End If 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 Dim shetoptions As Long shetoptions = 1 'include flat-pattern geometry Dim modelType As Long modelType = swModel.GetType If modelType = swconst.swDocPART Then Dim RootPath As String: RootPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\")) Dim result As Boolean result = swModel.ExportToDWG2(RootPath & "FlatTest.dwg", swModel.GetPathName, 1, True, varAlignment, False, False, shetoptions, Nothing) Else swApp.SendMsgToUser2 "Is not a part file.", swMbWarning, swMbOk End If Exit Sub End Sub
Thanks in advance!