AnsweredAssumed Answered

ExportToDWG2 changes the file when iterating through configurations

Question asked by MARCO TULIO RAMOS FILHO on Jul 4, 2019

I have this part file with multiple configurations. I would like to export the flatten surfaces to dxf.

When I run the macro, iterating through the configurations, it changes the model. It gets the flatten surface of the first configuration and applies to all others configurations.

If I change the configuration manually and execute the instruction to export (ExportToDWG2), it works perfectly.


Note: For test purposes, only the "N-0003" configuration has a flatten surface.


Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Sub main()
   Dim vConfNameArr As Variant
   Dim sConfigName As String
   Dim nStart As Single
   Dim i As Long
   Dim bShowConfig As Boolean
   Dim bRebuild As Boolean
   Set swApp = Application.SldWorks
   Set swModel = swApp.ActiveDoc
   vConfNameArr = swModel.GetConfigurationNames
   For i = 0 To UBound(vConfNameArr)
       sConfigName = vConfNameArr(i)
       bShowConfig = swModel.ShowConfiguration2(sConfigName)
       bRebuild = swModel.ForceRebuild3(False)
   Next i

End Sub

Sub Export2DXF()

   Dim FilePath                As String
   Dim PathSize                As Long
   Dim PathNoExtension         As String
   Dim NewFilePath             As String
   Dim dataAlignment(11)       As Double
   Dim varAlignment            As Variant
   Dim swPart                  As PartDoc
   dataAlignment(0) = 0#
   dataAlignment(1) = 0#
   dataAlignment(2) = 0#
   dataAlignment(3) = 1#
   dataAlignment(4) = 0#
   dataAlignment(5) = 0#
   dataAlignment(6) = 0#
   dataAlignment(7) = 1#
   dataAlignment(8) = 0#
   dataAlignment(9) = 0#
   dataAlignment(10) = 0#
   dataAlignment(11) = 1#
   varAlignment = dataAlignment
   Set swPart = swModel
   FilePath = swModel.GetPathName
   PathSize = Strings.Len(FilePath)
   PathNoExtension = Strings.Left(FilePath, PathSize - 6)
   NewFilePath = PathNoExtension + sConfigName & ".DXF"
   'Exportar Padrão Planificado
   options = 1
   bRet = swPart.ExportToDWG2(NewFilePath, FilePath, swExportToDWG_ExportSheetMetal, True, varAlignment, False, False, options, Null)

End Sub


Edit: Behaviour description and title correction.