AnsweredAssumed Answered

Pack and GO API- File rename doesn't work

Question asked by Viswanath Rangubhatla on Apr 20, 2015
Latest reply on Apr 21, 2015 by Santosh Pawar

I'm using pack and go API from the example and it doesn't seem to work to rename the files. it copies with original file names. When I checked pgSetFileNames(i) output the names are correct but it seems to fail rename.

However it works when a prefix and suffix is given.

I tried the macro given in this forum and followed the discussions but couldn't fix. I'm using SW2014.

 

My code is as below. Any help is appreciated.

 

 

swApp = CreateObject("SldWorks.Application")

' Open assembly
openFile = "C:\test.SLDASM"
swModelDoc = swApp.OpenDoc6(openFile, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
swModelDocExt = swModelDoc.Extension

 

' Get Pack and Go object
swPackAndGo = swModelDocExt.GetPackAndGo

 

' Get number of documents in assembly
namesCount = swPackAndGo.GetDocumentNamesCount

 

' Include any drawings and simulation results
swPackAndGo.IncludeDrawings = True


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

status = swPackAndGo.GetDocumentNames(pgFileNames)
     

 

' Get current save-to paths and filenames of the assembly's documents
status = swPackAndGo.GetDocumentSaveToNames(pgFileNames, pgFileStatus)
      
' Folder where to save the files
myPath = "C:\packngotest\"


' Create your own filenames for the model's documents
ReDim pgSetFileNames(namesCount - 1)

      
j = 0

 

For i = 0 To (namesCount - 1)
myFileName = pgFileNames(i)

' Determine type of SolidWorks file based on file extension
If InStr(LCase(myFileName), "sldprt") > 0 Then

myFileName = "777-test-0" & j & ".sldprt"
ElseIf InStr(LCase(myFileName), "sldasm") > 0 Then
myFileName = "777-test-0" & j & ".sldasm"
ElseIf InStr(LCase(myFileName), "slddrw") > 0 Then
myFileName = "777-test-0" & j & ".slddrw"
Else


' Only packing up SolidWorks files
Exit Function
End If


'  pgSetFileNames(i) = myPath & myFileName
pgSetFileNames(i) = myFileName
MsgBox("    My path and filename is: " & pgSetFileNames(i))
j = j + 1
Next i

     

status = swPackAndGo.SetSaveToName(True, myPath)

      
status = swPackAndGo.SetDocumentSaveToNames(pgSetFileNames)

MsgBox(status) ''it returns false"
statuses = swModelDocExt.SavePackAndGo(swPackAndGo)

Outcomes