AnsweredAssumed Answered

How do I make this macro run as a Task?

Question asked by Mike Sveda on Mar 20, 2014
Latest reply on Mar 20, 2014 by Steven Dod

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

Outcomes