4 Replies Latest reply on May 5, 2018 5:57 AM by Mohammad Darabseh

    Pack & Go saves lowercase file names

    Michael Chamerski

      Hi all -


      I'm having a bit of trouble trying to get proper case file names out of Pack and Go using a macro. I've gone through forum after forum trying to search for an answer (for example, using Dir() still doesn't fix the issue) and haven't been able to find a solution.


      This is the code I'm using in my Pack & Go section:


      Set swPackAndGo = swModelDocExt.GetPackAndGo

          namesCount = swPackAndGo.GetDocumentNamesCount


          ' Settings: Include any drawings and simulation results or others

          swPackAndGo.IncludeDrawings = True

          swPackAndGo.IncludeSimulationResults = True

          swPackAndGo.IncludeToolboxComponents = True


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

          status = swPackAndGo.GetDocumentNames(pgFileNames)

          status = swPackAndGo.GetDocumentSaveToNames(pgFileNames, pgFileStatus)


          ' Folder where to save the files

          MyPath = "C:\temp\"


          ReDim pgSetFileNames(namesCount - 1)


          For i = 0 To (namesCount - 1)


                   Dim myFileName As String

                   ' pgFileNames(i) = Dir(pgFileNames(i))

                   myFileName = Dir(pgFileNames(i))


                   pgSetFileNames(i) = MyPath & myFileName

                   Print #N, Now() & " Exporting: " & pgSetFileNames(i)


          Next i


          status = swPackAndGo.SetSaveToName(True, MyPath)

          ' swPackAndGo.FlattenToSingleFolder = True <-- Tried using this...still doesn't work.

          status = swPackAndGo.SetDocumentSaveToNames(pgSetFileNames)


          ' Pack and Go

          statuses = swModelDocExt.SavePackAndGo(swPackAndGo)


      The interesting bit is that I get proper case file names when printing from pgSetFileNames, but for some reason either SetSaveToName or SetDocumentSaveToNames is formatting everything to lowercase. Anyone have ideas on how to proceed?

        • Re: Pack & Go saves lowercase file names
          Michael Chamerski

          Upon some further investigation, the culprit seems to be SaveToName. Manually performing these selections, I notice an "Ignore Case" checkbox that is always checked by default. As of now, I have yet to see possible setting for this through the API.


          I'm trying to avoid using SaveToName by getting rid of IncludeDrawings, but this always results in no files being saved whatsoever. No matter what I do, it seems I NEED to use SaveToName.

            • Re: Pack & Go saves lowercase file names
              Cad Admin



              You can force your myFileName string to uppercase using UCASE(...) 


              You can add it in: pgSetFileNames(i) = MyPath & UCASE(myFileName)


              So regardless of input the output of the string will always be Uppercase

                • Re: Pack & Go saves lowercase file names
                  Michael Chamerski

                  Hi there -


                  I've tried the following:


                  pgSetFileNames(i) = MyPath & UCASE(myFileName) 'where myFileName = pgFileNames(i)

                  pgSetFileNames(i) = MyPath & Dir(pgFileNames(i))

                  pgSetFileNames(i) = MyPath & myFileName 'where myFileName = Dir(pgFileNames(i))

                  pgSetFileNames(i) = MyPath & myFileName 'where myFileName = UCASE(pgFileNames(i))


                  None of these methods work because it seems that SetSaveToName is overriding any changes I make.

                    • Re: Pack & Go saves lowercase file names
                      Mohammad Darabseh


                      I faced the same problem and none of answers on forums worked for me,

                      As a workaround you can let the VBA rename the files from lowercase to uppercase, and since windows files are not case sensitive, the references in SolidWorks will not be affected, Add the following lines to your code:




                      ReDim pgGetFileNames(namesCount - 1)

                      ReDim pgDocumentStatus(namesCount - 1)

                      status = swPackAndGo.GetDocumentSaveToNames(pgGetFileNames, pgDocumentStatus)





                      ' Pack and Go

                      statuses = swModelExt.SavePackAndGo(swPackAndGo)

                      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Add the following lines after Pack and go command   

                      For i = 0 To (namesCount - 1) '''''''''''''change lowecase to uppercase



                              Name pgGetFileNames(i) As UCase(pgGetFileNames(i))    ' Rename file.

                                   If (Right(UCase(pgGetFileNames(i)), 7) = ".SLDPRT") Then

                                      DRAW = Replace(UCase(pgGetFileNames(i)), "SLDPRT", "SLDDRW")

                                      If Dir(DRAW) <> "" Then Name DRAW As UCase(DRAW)

                                  End If

                          Next i