12 Replies Latest reply on Jul 20, 2016 8:34 AM by Joe Tharion

    Pack and Go Macro Converts All the Filenames to Lower Case

    David Sheridan

      Hello,

       

      When I run a Pack and Go macro all the filenames are converted to Lower Case.

       

      The macro code is located at:

      http://help.solidworks.com/2015/English/api/sldworksapi/Pack_and_Go_an_Assembly_Example_VB.htm

       

      All the filenames (the SolidWorks default part numbers) are converted to lower case.

       

      This does not happen when I do a Pack and Go from the user interface menu.

       

      I would like the file names to remain the same case so the Bill of Materials are not changed, but if the filenames are changed then upper case would be better than lower case.

       

      Any ideas on how to prevent the macro from converting the filenames to lower case?

       

      Thanks,

       

      Dave

        • Re: Pack and Go Macro Converts All the Filenames to Lower Case
          David Sheridan

          I added the underlined lines below to make all file names and extensions upper case.

           

          ' 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)

           

                   pgFileNames(i) = UCase(pgFileNames(i))

           

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

              Next i

          End If

           

          ' Set document paths and names for Pack and Go

          status = swPackAndGo.SetDocumentSaveToNames(pgFileNames)

          • Re: Pack and Go Macro Converts All the Filenames to Lower Case
            Deepak Gupta

            Using the same example and sample file (given the macro) I didn't see any case changed for me.

             

            But looking at your reply I believe that issue has been resolved. Thanks for sharing the codes.

              • Re: Pack and Go Macro Converts All the Filenames to Lower Case
                David Sheridan

                Hi Deepak,

                 

                Thank you for taking time to investigate my issue.  You are correct.  If I use the example code it does not change the case of the filenames.  I changed the code to pack and go the assembly or part that I have opened by changing "Set swModelDoc", see below.

                 

                 

                'openFile = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\advdrawings\handle.sldasm"

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

                 

                Set swModelDoc = swApp.ActiveDoc

                 

                Then an assembly or part will pack and go to all lowercase.  I may be using "Set swModelDoc" incorrectly.  Any ideas?

                 

                Note:

                On my SW install "C:\Program Files\SolidWorks Corp\SOLIDWORKS\samples\tutorial\advdrawings\handle.sldasm" and its parts are all lower case file names.

                connector.sldprt

                handle rod.sldprt

                marble handle.sldprt

                knob.sldprt

                 

                Thanks,

                 

                Dave

              • Re: Pack and Go Macro Converts All the Filenames to Lower Case
                Keith Rice

                Does IPackAndGo::GetDocumentNames get the paths with the correct case?

                Do the cases used with the strings in IPackAndGo::SetDocumentSaveToNames remain intact after the pack and go?

                 

                If yes to both then the problem is solved with some string manipulation, quite similar to what you're already doing. Otherwise, you'll need to rename the files using the correct case after the pack and go occurs.

                 

                Keith

                SolidWorks API Tutorials

                  • Re: Pack and Go Macro Converts All the Filenames to Lower Case
                    David Sheridan

                    Hi Keith,

                     

                    GetDocumentNames get the paths with the wrong case.

                     

                    I use:

                    ' 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)

                     

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

                     

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

                        Next i

                    End If

                     

                    ' Set document paths and names for Pack and Go

                    status = swPackAndGo.SetDocumentSaveToNames(pgFileNames)

                     

                    SetDocumentSaveToNames uses the lower case path which is OK for me and pgFileNames(i) = Dir(pgFileNames(i)) keeps the file name and extension to the correct case.  Even though pgFileNames(i) = Dir(pgFileNames(i)) has no path, the correct path is maintained with status = swPackAndGo.SetDocumentSaveToNames(pgFileNames).

                     

                    Thanks,

                    Dave

                      • Re: Pack and Go Macro Converts All the Filenames to Lower Case
                        Joe Tharion

                        Hi,


                        I have been having the same issue, but can't seem to find out where I have gone wrong. I have implemented the code above, but it is spliced into my other macro code:

                         

                        ' 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)

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

                                'pgFileNames(i) = UCase(pgFileNames(i)) 'Force Upper Case File Names

                                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)

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

                                'pgFileNames(i) = UCase(pgFileNames(i)) 'Force Upper Case File Names

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

                                Next i

                            End If

                           

                            status = swPackAndGo.SetDocumentSaveToNames(pgFileNames)

                            swPackAndGo.IncludeDrawings = True 'Include drawings

                            swPackAndGo.FlattenToSingleFolder = True ' Flatten the Pack and Go folder structure; save all files to the root directory

                            swPackAndGo.SetSaveToName True, MyPath & "\" & name & "-" & Rev & ".zip" 'Save as a ZIP file

                            vStatus = modelDoc.Extension.SavePackAndGo(swPackAndGo) 'Save the pack and go

                         

                        As, when I do it, I make a ZIP file and write a revision into the zip file also. I have tried forcing upper case, using the dir command, but both dont seem to work.  I have run the debugger, and when I look at the filenames/path it is upper case, but in the ZIP file created, thefile names are lower case.

                         

                        Any thoughts where I have gone wrong??

                         

                        thanks,

                        Joe