Problem saving Solidworks files inside PDM vault using macro

57 Views Asked by At

I'm afraid my question may be too specific but I really don't know how to solve this problem without help. I'm creating a SolidWorks vba macro to name and save new models inside the PDM vault. The macro uses the built in SaveAs3 method and allows the user to select various save options: Save as, Save as copy and continue and Save as copy and open. The problems are as follows:

  • Once saved, the PDM datacard does not pop up automatically as when you save a file normally. This is a negligible problem except that I believe it is connected to the following more serious ones.
  • When the user fills in the datacard of a file saved in this way and then check in it, the file loses all the data saved in the datacard. Checking out the file, refilling the datacard, and checking in it again keeps the datacard correctly filled out.

Below a cleaned version of my code that i'm using for tests:

Option Explicit

Const newModelName As String = "C:\VaultName\FolderName\ModelName.SLDPRT"
Const tipo As Long = swDocPART 'swDocASSEMBLY

'This option changes depending on which test I want to run. I switch between them commenting one or the other.
Const opzioni As Long = swSaveAsOptions_Copy
'Const opzioni As Long = swSaveAsOptions_CopyAndOpen

Sub main()
    
    UserForm1.Show
    
End Sub

Sub SalvaNuovoCodice()

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

    If swModel.SaveAs3(newModelName, swSaveAsCurrentVersion, opzioni) = 0 Then

        'If I use the option swSaveAsOptions_Copy and I want to open the file after the save I use the line below. In this test version I just comment it if I don't need it.
        Set swModel = swApp.OpenDoc(newModelName, tipo)
        
    Else
    
        MsgBox "Il salvataggio non è andato a buon fine."
        
    End If

End Sub

i have also tried to check if the file is Locked accessing the vault, but it did not lead me to any solution. It seems to me that the built in method to save a file (SaveAs3) have issues saving files inside the Vault. It's a weird thing, since the PDM Vault is made by the same guys that made SolidWorks. I've tried to ask the same question in the official forum but with no result.

Can you help me?

0

There are 0 best solutions below