Page 1 of 1

Solidworks PDM - Delete checked-in file with VBA

Posted: Tue Jun 04, 2024 10:50 pm
by Jacomuller
I am trying to delete a file from the PDM but it is not working for me. This is the code I have:

' DeleteFile = sPathName & DeleteFileFilter ' sFileName 'DeleteFileFilter
' If Dir(DeleteFile) <> "" Then
' 'MsgBox "This File Exists"
' If Len(Dir(DeleteFile)) > 0 Then
' SetAttr Left(sPathName, Len(sPathName) - 1), vbNormal
' Kill DeleteFile
' End If
' End If
If the file is check-in it will just hang up on me. If the file is checked out by me, it will delete the file. I think it is just deleting the local file and not the file in the PDM Vault - maybe not sure.
Any ideas?

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Wed Jun 05, 2024 8:18 am
by AlexB
I believe you're going to have to use the API to do this properly.

See help page for API command to delete a file. The example linked on this help page shows how to delete a file.
https://help.solidworks.com/2020/englis ... efile.html

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Wed Jun 05, 2024 8:03 pm
by Jacomuller
@AlexB thanks. I saw that one yesterday. It is a very handy utility. I will grab the parts I need from the VB and use that in my VBA macro. My macro does a lot of things of which the "delete the PDF in the PDM" is just a small part. I suppose I was lazy and looking for a quick fix :) . I will give it a go when I have a bit of free time. thanks again.

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Thu Jun 06, 2024 12:25 pm
by bnemec
At the risk of being Capt. Obvious, maybe test this when you're logged into the vault as Admin so you don't have to worry about permissions. Once it's working log in as a regular user in the group that would normally use it and test again. I only mention this because I've lost too much time looking for the problem in my code when it was just permissions.

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Thu Jun 06, 2024 3:01 pm
by mp3-250
accessing files outside explorer is likely to delete the local cache.

I use this technique to cleanup the local cache from the command prompt.
to access the real local cache folder content adding / at the end of the address bar path end in wundows explorer and press enter or just use command prompt or a file explorer like totalcommander, doublecommander etc. so you could monitor in resl time what is happening.

in theory you should use pdm api to

1. login in the vault (with current logged user is automatic otherwise you have to supply username and psw)
2. get the file id (sql unique id) from tge file path
3. delete the file

delete file is a db operation, you do not even need to retrieve the file inside your local cache to begin with.

also note that you need the pdm library reference in vba (or better use late binding), but almost all the documentation is focused on vb.net stand alone applications so for the use of pdm in vba you should experiment a bit with a simpler code.

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Tue Jun 11, 2024 6:17 pm
by Jacomuller
My code for testing to delete a file from the PDM is:
image.png
there is a "run-time error 91" at the line starting with "Set Myfile.."

Am I missing something in the code?

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Wed Jun 12, 2024 7:38 am
by SPerman
The examples I find on the solidworks website all use "GetFileFromPath". I know that doesn't answer your question, but it might be a easier way to solve the problem.

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Wed Jun 12, 2024 8:29 am
by AlexB
Jacomuller wrote: Tue Jun 11, 2024 6:17 pm there is a "run-time error 91" at the line starting with "Set Myfile.."

Am I missing something in the code?
I am able to get this working with your code. In order to try to replicate your error, I passed bad values in for the folder path and for the file path. The bad value for the folder path produced the issue you're seeing. I'm guessing that your `MyFolder` is set to `Nothing` when you're trying to call `GetFile` with it.

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Wed Jun 12, 2024 5:54 pm
by mp3-250
As a side note to delete a file from the vault you do not need to get it. just delete it otherwise you have to delete the local copy too (which is optional)

Re: Solidworks PDM - Delete checked-in file with VBA

Posted: Thu Jun 13, 2024 9:58 pm
by Jacomuller
>< Thanks @AlexB , I had a typo in the way I construct the file path. it is now working fine.