1 Reply Latest reply on Mar 20, 2014 4:29 PM by Steven Dod

    How do I make this macro run as a Task?

    Mike Sveda

      I have no API training.  I am not sure how to modify this macro to run as a task.   I've tried searching help files and no luck.

       

      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)

         

             

      bShowConfig = swModel.ShowConfiguration2(sConfigName)

       

      bRebuild = swModel.ForceRebuild3(False)

       

       

      Dim FilePath As String

      Dim PathSize As Long

      Dim PathNoExtension As String

      Dim NewFilePath As String

      Dim StartPos As Integer

      Dim FilenameNoExt As String

       

       

      FilePath = swModel.GetPathName

      PathSize = Strings.Len(FilePath)

      PathNoExtension = Strings.Left(FilePath, PathSize - 6)

      StartPos = InStrRev(FilePath, "\") + 1

       

      FilenameNoExt = Mid(FilePath, StartPos, Len(FilePath) - 5 - StartPos)

       

      'NewFilePath = PathNoExtension + sConfigName & ".DXF"

      NewFilePath = "S:\Manufacturing\Cutting Dept\Laser Waterjet Approved DXFs\Sheet Metal DXF\" + FilenameNoExt + sConfigName & ".DXF"

       

       

      'Export Flat Pattern

      bRet = swModel.ExportFlatPatternView(NewFilePath, 1)

       

      Next i

      End Sub

        • Re: How do I make this macro run as a Task?
          Steven Dod

          I am just guessing but I think you want to run it as an EPDM task, like after an approval?  If this is true, add a Task in the EPDM Administration program using the SWTaskAddIn.  There is a place for you to copy and paste your script into.  Then you can go to a workflow transition and add an Action to Execute this task automatically (i.e. just before Approved).

          Capture.PNG

          Hope this helps...