3 Replies Latest reply on Oct 9, 2013 8:53 AM by Emil Svallingson

    How to hard code save location in a EPDM Task Script

    Emil Svallingson

      Hi,

       

      I have the following scipt which is working great. However I want the outcome ( a part file and a step file) to end up in the L:\Temp folder, always. How do I hard code that in?

       

      This is script right now:

       

      Dim swApp          As SldWorks.SldWorks
      Dim swModel        As SldWorks.ModelDoc2
      Dim swModelDocExt  As SldWorks.ModelDocExtension
      Dim FilePath        As String
      Dim sFilePath      As String
      Dim PathSize        As Long
      Dim PathNoExtensionAs String
      Dim NewFilePath    As String
      Dim nErrors        As Long
      Dim nWarnings      As Long

       

      Sub main()

       

      Set swApp = Application.SldWorks

      'Set swModel = swApp.ActiveDoc

      Set swModel = swApp.OpenDoc6("<Filepath>", SwConst.swDocASSEMBLY, 3, "", nErrors, nWarnings)

       

      Set swModelDocExt = swModel.Extension

       

      FilePath = swModel.GetPathName

      PathSize = Strings.Len(FilePath)

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

      NewFilePath = PathNoExtension & "SLDPRT"

       

      swApp.SetUserPreferenceIntegerValue swSaveAssemblyAsPartOptions, swSaveAsmAsPart_ExteriorFaces

      swModelDocExt.SaveAs NewFilePath, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings

      'swApp.CloseDoc swModel.GetTitle

       

      Set swModel = swApp.OpenDoc6(NewFilePath, SwConst.swDocPART, 3, "", nErrors, nWarnings)

      Set swModel = swApp.ActiveDoc

       

      sFilePath = PathNoExtension & "STEP"

      swModel.SaveAs (sFilePath)

      swApp.CloseDoc swModel.GetTitle

       

      End Sub

        • Re: How to hard code save location in a EPDM Task Script
          Emil Svallingson

          Okej, I finally managed to do it, posting it here so others may take advantage of the work, not the prettiest code but it works:

           

          Sub main()

          Dim swApp               As SldWorks.SldWorks

          Dim swModel             As SldWorks.ModelDoc2

          Dim swModelDocExt       As SldWorks.ModelDocExtension

          Dim FilePath            As String

          Dim sFilePath           As String

          Dim PathSize            As Long

          Dim PathNoExtension     As String

          Dim NewFilePath         As String

          Dim nErrors             As Long

          Dim nWarnings           As Long

           

          Set swApp = Application.SldWorks

          swApp.Visible = True

          Dim myFilePath as String

          myFilePath = "<Filepath>"

          Set swModel = swApp.OpenDoc6(myFilePath, 2, 1, "", nerrors, nwarnings)

          Set swModelDocExt = swModel.Extension

           

          Path = "L:\Temp\"

          FileName = Right(swModel.GetPathName, (Len(swModel.GetPathName) - InStrRev(swModel.GetPathName, "\")))

           

          PathSize = Strings.Len(FileName)

          FileNameNoExtension = Strings.Left(FileName, PathSize - 6)

          NewFilePath = Path & FileNameNoExtension & "SLDPRT"

           

           

          swApp.SetUserPreferenceIntegerValue 201, 3

          swModelDocExt.SaveAs NewFilePath, 0, 1, Nothing, nErrors, nWarnings

           

           

          swApp.CloseDoc swModel.GetTitle

           

           

          Set swModel = swApp.OpenDoc(NewFilePath, 1)

          Set swModel = swApp.ActiveDoc

           

           

          sFilePath = Path & FileNameNoExtension & "STEP"

           

          swModel.SaveAs (sFilePath)

           

           

          swApp.CloseDoc swModel.GetTitle

           

          End Sub

            • Re: How to hard code save location in a EPDM Task Script
              Deepak Gupta

              Here is more simplified version of the macro:

               

              Option Explicit

              Dim swApp               As SldWorks.SldWorks

              Dim swModel            As SldWorks.ModelDoc2

              Dim sFileName         As String

              Dim myFilePath        As String

              Dim nErrors             As Long

              Dim nWarnings        As Long

              Const Path              As String = "L:\Temp\"

               

              Sub main()

               

              Set swApp = Application.SldWorks

              swApp.Visible = True

              myFilePath = "<Filepath>"

               

              Set swModel = swApp.OpenDoc6(myFilePath, 2, 1, "", nErrors, nWarnings) 'Open Specified File

              sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1) ' Get File Name with extension

              sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1) ' Remove File Extension

               

              swApp.SetUserPreferenceIntegerValue 201, 3 'Set Exterior Faces option

              swModel.Extension.SaveAs Path & sFileName & ".SLDPRT", 0, 1, Nothing, nErrors, nWarnings 'Save as part

               

              swApp.CloseDoc swModel.GetTitle

               

              Set swModel = swApp.OpenDoc(Path & sFileName & ".SLDPRT", 1) 'Open New File

              Set swModel = swApp.ActiveDoc

              swModel.SaveAs (Path & sFileName & ".STEP") ' Save as Step

              swApp.CloseDoc swModel.GetTitle

               

              End Sub