6 Replies Latest reply on Apr 29, 2014 5:25 PM by Colin Brue

    Task exporting flat pattern to DXF

    tyty tyty

      Hello,

       

      i created a task to directly export the flat pattern to DXF but code not work

       

      Can anybody tell me what's wrong?

       

       


      Option Explicit

      Sub main()

          Dim swApp                   As SldWorks.SldWorks
          Dim swModel                 As SldWorks.ModelDoc2
          Dim vConfNameArr            As Variant
          Dim sConfigName             As String
          Dim nStart                  As Single
          Dim i                       As Long
          Dim bShowConfig             As Boolean
          Dim bRebuild                As Boolean
          Dim bRet                    As Boolean
          Dim CurFeature              As SldWorks.Feature

          Set swApp = CreateObject("SldWorks.Application")
          Set swModel = swApp.ActiveDoc

      ' Is document active?

      If swModel Is Nothing Then

          swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk

          Exit Sub

      End If


      ' Is it a part document?

      Dim modelType As Long

      modelType = swModel.GetType

      If modelType <> SwConst.swDocPART Then

          swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk

          Exit Sub

      End If

       

              vConfNameArr = swModel.GetConfigurationNames

          For i = 0 To UBound(vConfNameArr)

              sConfigName = vConfNameArr(i)
         
          If Right(sConfigName, 15) = "SM-FLAT-PATTERN" Then
         Else
      bShowConfig = swModel.ShowConfiguration2(sConfigName)

      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 - 6)

      NewFilePath = PathNoExtension + sConfigName & ".DXF"

      'Export Flat Pattern
      bRet = swModel.ExportFlatPatternView(NewFilePath, 1)
      End If
      Next i
      End
      End Sub

        • Re: Task exporting flat pattern to DXF
          Deepak Gupta

          What is this line doing

           

          If Right(sConfigName, 15) = "SM-FLAT-PATTERN" Then?? You need to define something I guess after Then (sorry but I've limited knowledge with API)

           

          Can you try the codes posted here: https://forum.solidworks.com/message/124033#124033

            • Re: Task exporting flat pattern to DXF
              tyty tyty

              The code generates separate dxf for each part configuration. I'm using the SolidWorks Task add-in to execute the following script:

               

               

               

              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

               

              Option Explicit

              Dim swApp As SldWorks.SldWorks

              Dim i As Long

              Dim swModel As SldWorks.ModelDoc2

              Dim vConfNameArr As Variant

              Dim vConfigName As String

              Dim bShowConfig As Boolean

              Dim bRebuild As Boolean

              Dim bRet As Boolean

              Dim swDocSpecification As SldWorks.DocumentSpecification

              Dim aa As String

              Sub main()

               

              aa = "<Filepath>"

              Set swApp = CreateObject("SldWorks.Application")

              Set swDocSpecification = swApp.GetOpenDocSpec(aa)

              Set swModel = swApp.OpenDoc7(swDocSpecification)

              Set swModel = swApp.ActiveDoc

               

              'Is it a part document?

              Dim modelType As Long

              modelType = swModel.GetType

              If modelType <> SwConst.swDocPART Then

              swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk

              Exit Sub

              End If

              vConfNameArr = swModel.GetConfigurationNames

              '===========================

              For i = 0 To UBound(vConfNameArr)

              vConfigName = vConfNameArr(i)

              If Right(vConfigName, 15) = "SM-FLAT-PATTERN" Then

              Else

              bShowConfig = swModel.ShowConfiguration2(vConfigName)

              bRebuild = swModel.ForceRebuild3(False)

                

              Dim FilePath As String

              Dim NewFilePath As String

              FilePath = "<path>"

              NewFilePath = FilePath & "\" & vConfigName & ".DXF"

              bRet = swModel.ExportFlatPatternView(NewFilePath, swExportFlatPatternOption_RemoveBends)

              End If

              'Next vConfigName

              Next i

              'swApp.CloseDoc (swModel.GetTitle)

               

              End Sub

                • Re: Task exporting flat pattern to DXF
                  Deepak Gupta

                  tyty tyty wrote:

                   

                   

                  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

                  I'm not sure how to handle it with EPDM

                    • Re: Task exporting flat pattern to DXF
                      Colin Brue

                      I made use of your code above and modified it a little bit.  I think your main issue was a misplaced ELSE command.  The main code was only executing on configurations that weren't SM-FLAT-PATTERN.  This code has been working for me today, running it as a task in PDM.  It is very specific and has no error handling.  This is ugly code, likely not for general use but it fits my needs, and I think this could fit yours too Tyty tyty.

                       

                      I could not get the other codes listed at other links below to run for me.  My code listed below:

                       

                       

                      Option Explicit

                      Dim swApp As SldWorks.SldWorks

                      Dim i As Long

                      Dim swModel As SldWorks.ModelDoc2

                      Dim vConfNameArr As Variant

                      Dim vConfigName As String

                      Dim bShowConfig As Boolean

                      Dim bRebuild As Boolean

                      Dim bRet As Boolean

                      Dim swDocSpecification As SldWorks.DocumentSpecification

                      Dim aa As String

                      Dim docfilename as string

                      Sub main()

                      aa ="<Filepath>"

                      docfilename =MID(aa, InStrRev(aa,"\")+1)

                      docfilename =LEFT(docfilename, LEN(docfilename)-7)

                      Set swApp = CreateObject("SldWorks.Application")

                      Set swDocSpecification = swApp.GetOpenDocSpec(aa)

                      Set swModel = swApp.OpenDoc7(swDocSpecification)

                      Set swModel = swApp.ActiveDoc

                      'Is it a part document?

                      Dim modelType As Long

                      modelType = swModel.GetType

                      If modelType <> SwConst.swDocPART Then

                      Exit Sub

                      End If

                      vConfNameArr = swModel.GetConfigurationNames

                      '===========================

                      For i = 0 To UBound(vConfNameArr)

                      vConfigName = vConfNameArr(i)

                      If Right(vConfigName, 15) = "SM-FLAT-PATTERN" Then

                      bShowConfig = swModel.ShowConfiguration2(vConfigName)

                      bRebuild = swModel.ForceRebuild3(False)

                       

                      Dim FilePath As String

                      Dim NewFilePath As String

                      FilePath = "c:\pdm\test\testdxfexports\"

                      'following line would save it to the same path location with the same name and .dxf

                      'NewFilePath = LEFT(aa,(LEN(aa)-7)) & ".DXF"

                      'following line would save it to a specified location with the same file name and .dxf

                      NewFilePath = FilePath & docfilename & ".DXF"

                      bRet = swModel.ExportFlatPatternView(NewFilePath, swExportFlatPatternOption_RemoveBends)

                      End If

                      Next i

                      End Sub

                • Re: Task exporting flat pattern to DXF
                  Andreas Ravn

                  Here are the threads i've found so far that brings up the problem and has code examples.


                  I've been experimenting with both Michael Woerthers and Tyty's code examples for using the ExportFlatPatternView methos in a EPDM task script. No luck so far.

                   

                  https://forum.solidworks.com/message/308542#308542
                  https://forum.solidworks.com/message/243051#243051
                  https://forum.solidworks.com/message/273904#273904

                   

                   

                  Just giving this a bump.

                   

                   

                  Andreas