Solidworks PDM - Delete checked-in file with VBA

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Solidworks PDM - Delete checked-in file with VBA

Unread post 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?
by AlexB » Wed Jun 12, 2024 8:29 am
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.
Go to full post
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

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

Unread post 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
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

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

Unread post 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.
User avatar
bnemec
Posts: 1944
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2548
x 1400

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

Unread post 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.
User avatar
mp3-250
Posts: 631
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 706
x 347

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

Unread post 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.
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

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

Unread post 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?
Attachments
image.png
User avatar
SPerman
Posts: 2056
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2227
x 1878
Contact:

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

Unread post 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.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
AlexB
Posts: 501
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 445

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

Unread post 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.
User avatar
mp3-250
Posts: 631
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 706
x 347

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

Unread post 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)
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

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

Unread post by Jacomuller »

>< Thanks @AlexB , I had a typo in the way I construct the file path. it is now working fine.
Post Reply