0 Replies Latest reply on Nov 16, 2018 9:46 AM by Rainar Poleoluline

    Browse file for pack and go and set the recording location?

    Rainar Poleoluline


      I need help. I try to learn the API and macros, but it`s still complicated. I downloaded one macro: "Pack and go". It`s working fine, but I want it to be more comfortable to use.

      Steps what I want to do:

      1. open solidworks (today 2017 but soon I have 2019)

      2. I press the macro "pack and go" button

      3. Then, I want to browse a solidworks file

      4. Then I want to choose location for save

      5. END

      And one small thing more - why does this macro change the letters size in file name?


      Macro code is here:


      Sub main()


      Set swApp = Application.SldWorks


      ' Open assembly

      openFile = "c:\Users\me\Documents\Folder 1\Subfolder 1\Subfolder 2\File name.sldasm"

      Set swModelDoc = swApp.OpenDoc6(openFile, swDocASSEMBLY, swOpenDocOptions_Silent, "", errors, warnings)

      Set swModelDocExt = swModelDoc.Extension


      ' Get Pack and Go object

      Debug.Print "Pack and Go"

      Set swPackAndGo = swModelDocExt.GetPackAndGo


      ' Get number of documents in assembly

      namesCount = swPackAndGo.GetDocumentNamesCount


      Debug.Print " number of model documents: " & namesCount


      ' Include any drawings, SOLIDWORKS Simulation results, and SOLIDWORKS Toolbox components

      swPackAndGo.IncludeDrawings = True


      Debug.Print " Include drawings " & swPackAndGo.IncludeDrawings


      swPackAndGo.IncludeSimulationResults = True

      Debug.Print "  Include SOLIDWORKS Simulation results: " & swPackAndGo.IncludeSimulationResults

      swPackAndGo.IncludeToolboxComponents = True

      Debug.Print "  Include SOLIDWORKS Toolbox components: " & swPackAndGo.IncludeToolboxComponents


      ' Get current paths and filenames of the assembly's documents

      status = swPackAndGo.GetDocumentNames(pgFileNames)

      Debug.Print ""

      Debug.Print "  Current path and filenames: "

      If (Not (IsEmpty(pgFileNames))) Then

          For i = 0 To UBound(pgFileNames)

              Debug.Print "    The path and filename is: " & pgFileNames(i)

          Next i

      End If


      ' Get current save-to paths and filenames of the assembly's documents

      status = swPackAndGo.GetDocumentSaveToNames(pgFileNames, pgFileStatus)

      Debug.Print ""

      Debug.Print "  Current default save-to filenames: "

      If (Not (IsEmpty(pgFileNames))) Then

          For i = 0 To UBound(pgFileNames)

              Debug.Print "   The path and filename is: " & pgFileNames(i)

          Next i

      End If


      ' Set folder where to save the files

      myPath = "C:\Users\me\Documents\Folder 100\Subfolder 100\Subfolder 200"

      status = swPackAndGo.SetSaveToName(True, myPath)

      ' Flatten the Pack and Go folder structure; save all files to the root directory

      swPackAndGo.FlattenToSingleFolder = True



      ' Add a prefix to the new Pack and Go filenames

      swPackAndGo.AddPrefix = "SW_"

      ' Verify document paths and filenames after adding prefix

      ReDim pgGetFileNames(namesCount - 1)

      ReDim pgDocumentStatus(namesCount - 1)

      status = swPackAndGo.GetDocumentSaveToNames(pgGetFileNames, pgDocumentStatus)

      Debug.Print ""

      Debug.Print "  My Pack and Go path and filenames after adding prefix: "

      For i = 0 To (namesCount - 1)

           Debug.Print "    My path and filename is: " & pgGetFileNames(i)

      Next i

      ' Pack and Go

      statuses = swModelDocExt.SavePackAndGo(swPackAndGo)

      End Sub