Pack And Go Macro Returns Lowercase Letters

I have the code below, from Keith Rice, with I have modified a little bit to save the pack and go items into (current folder \\ history folder \\ filename folder). The only problem with this is it returns lowercase letters for all the files.  Is this something intrinsic with this method, or can it be made to output all capital letters?  I've seen the same question regarding the pack and go API, but not with with exact method.  Any help is greatly appreciated.  

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Dim strOutputFolder As String

'set output to current folder / history / filename
strOutputFolder = swApp.GetCurrentWorkingDirectory & "HISTORY" & "\\" & UCase(swModel.GetTitle)

'confirm current path
'swApp.SendMsgToUser (strOutputFolder)

If SaveAsPackAndGo(swApp, swModel, strOutputFolder) = False Then Exit Sub
End Sub

Function SaveAsPackAndGo(swApp As SldWorks.SldWorks, _
swModel As SldWorks.ModelDoc2, strOutputFolder As String) As Boolean

On Error GoTo ErrHandler

Dim swPackAndGo As SldWorks.PackAndGo
Dim intDocCount As Integer
Dim vPathNames As Variant
Dim strSetPathNames() As String
Dim i As Integer
Dim vStatus As Variant
Dim strRetVal As String

Set swPackAndGo = swModel.Extension.GetPackAndGo
swPackAndGo.SetSaveToName True, strOutputFolder

vStatus = swModel.Extension.SavePackAndGo(swPackAndGo)

'Determine whether pack and go was successful
For i = 0 To UBound(vStatus)
Select Case vStatus(i)
Case 0
strRetVal = "Pack and go succeeded"
Case 1
strRetVal = "User input not correct"
Case 2
strRetVal = "File already exists"
Case 3
strRetVal = "File to save is empty"
Case 4
strRetVal = "Save error"
End Select

If vStatus(i) <> 0 Then
swApp.SendMsgToUser "Pack and go fail reason: " & vbCrLf & strRetVal
SaveAsPackAndGo = False
Exit For
Else
SaveAsPackAndGo = True
End If

Next i

Exit Function

ErrHandler:
Debug.Print "ERROR: " & Err.Number & " " & Err.Description
swApp.SendMsgToUser "Unhandled error occurred while saving pack and go."
SaveAsPackAndGo = False
End Function

SolidworksApi/macros
Answers 7
AJ
AJ 2021-04-08 Best Answer

It does that to me too.

RG
RG 2021-04-08

I have solved how to pack to go and rename to all uppercase.  I used the code from my original message and added a few lines at the end which browse to the 'save to' folder and then renames all the files to uppercase.  I found this while searching for a windows VBA code to rename filenames to uppercase and then incorporated it into this code.  I attach the code as well as pasted it below. 

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPackAndGo As SldWorks.PackAndGo
Dim openFile As String

Dim pgFileNames As Variant

Dim pgFileStatus As Variant
Dim pgGetFileNames As Variant
Dim pgDocumentStatus As Variant

Dim pgSetFileNames() As String
Dim j As Long
Dim myFileName As String
Dim myFolder As String

Dim status As Boolean
Dim warnings As Long
Dim errors As Long
Dim i As Long
Dim namesCount As Long
Dim myPath As String
Dim statuses As Variant


Sub main()

Dim swModel As SldWorks.ModelDoc2
Dim swFilename As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

' Get Pack and Go object
Debug.Print "Pack and Go"
Set swPackAndGo = swModel.Extension.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 = False
Debug.Print " Include drawings: " & swPackAndGo.IncludeDrawings
swPackAndGo.IncludeSimulationResults = False
Debug.Print " Include SOLIDWORKS Simulation results: " & swPackAndGo.IncludeSimulationResults
swPackAndGo.IncludeToolboxComponents = False
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)
pgFileNames(i) = Dir(pgFileNames(i))
pgFileNames(i) = UCase(pgFileNames(i))
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))
Debug.Print " The path and filename is: " & (pgFileNames(i))
Next i
End If

' Set folder where to save the files

swFilename = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
swFilename = Left(swFilename, Len(swFilename) - 7)

myPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))
myPath = myPath & "HISTORY" & "\" & swFilename

status = swPackAndGo.SetSaveToName(True, myPath)

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

' Pack and Go
statuses = swModel.Extension.SavePackAndGo(swPackAndGo)

'BROWSES TO SAVE TO FOLDER AND CHANGES NAMES TO UPPERCASE

Dim file As Variant

file = Dir(myPath & "\")

While (file <> "")

Name myPath & "\" & file As UCase(myPath & "\" & file)

file = Dir()
Wend

End Sub

JB
JB 2021-04-08

Yeah, hate to bear bad news, but at least when you know you can (hopefully) create a countermeasure.

RG
RG 2021-04-08

Thanks for bumming me out Josh.  No, thank you though, that is good information to know.  The link to Jim Wilkinson's post is insightful. 

JB
JB 2021-04-08

Ryan Gaudreau wrote:

I've tried every way I could think of to revert it back to capital letters but nothing seems to work. Might just have to do it after the fact through a windows script or something. 

SolidWorks is not case-sensitive for filenames.  Neither is windows.  SW folks have stated (can't remember where) that you are basically SOL if you care about case in filenames.  

Pretty sure you won't be able to rename files in a Windows script with just a case change either.  Windows will not see myfile.sldprt -> MYFILE.SLDPRT as different, therefore the name change will fail.  You'll have to rename twice.

EDIT: Info from Jim Wilkinson here  -   

AJ
AJ 2021-04-08

Technically speaking renaming all the references' files should not break any references. As you said, you can write a script to do that. It will be very taxing performance-wise if your assembly is large.

RG
RG 2021-04-08

I've tried every way I could think of to revert it back to capital letters but nothing seems to work. Might just have to do it after the fact through a windows script or something.