I’m trying to create an EPDM task which generates dxf files for all sheet-metal parts passing specific workflow transition. The code generates separate dxf for each part configuration. I'm using the SolidWorks Task add-in to execute the following script:
Option ExplicitDim swApp As SldWorks.SldWorksSub main() Dim swModel As SldWorks.ModelDoc2 Dim vConfNameArr As Variant Dim vConfName As Variant Dim bShowConfig As Boolean Dim bRebuild As Boolean Dim bRet As Boolean Dim swDocSpecification As SldWorks.DocumentSpecification Set swApp = CreateObject("SldWorks.Application") Set swDocSpecification = swApp.GetOpenDocSpec("C:\Users\ananchev.TL-HQ\Desktop\sheetMetal.SLDPRT") Set swModel = swApp.OpenDoc7(swDocSpecification) Set swModel = swApp.ActiveDoc'Is it a part document?Dim modelType As LongmodelType = swModel.GetTypeIf modelType <> SwConst.swDocPART Then swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk Exit SubEnd IfvConfNameArr = swModel.GetConfigurationNamesFor Each vConfName In vConfNameArr bShowConfig = swModel.ShowConfiguration2(vConfName) bRebuild = swModel.ForceRebuild3(False) Dim FilePath As String Dim PathSize As Long Dim PathNoExtension As String Dim NewFilePath As String FilePath = swModel.GetPathName PathSize = Strings.Len(FilePath) 'PathNoExtension = Strings.Left(FilePath, PathSize - Len(swModel.GetTitle)) + "Export\" PathNoExtension = "C:\Users\ananchev.TL-HQ\Desktop\Tests\" + "Export\" NewFilePath = PathNoExtension + vConfName & ".DXF" 'Export Flat Pattern bRet = swModel.ExportFlatPatternView(NewFilePath, swExportFlatPatternOption_RemoveBends)Next vConfName'Close the documentswApp.CloseDoc (swModel.GetTitle)End Sub
When I run it as a macro within SolidWorks everything goes fine, but executed from my EPDM task it generates the dxf only for the first part configuration and then ends with an “The object invoked has disconnected from its clients.” error.
The debug option marks the line where the next part configuration is loaded in SWx.
I tried a lot of different options for the code, but each and every time the same behavior and error. I’m sure I’m missing something, but I can’t find it.