Page 1 of 1

Solidworks PDM API - add new folder

Posted: Fri Dec 01, 2023 12:24 pm
by Hansjoerg
Is it correct that the PDM API can only work with VB.Net and not with VBA?

Checking if a directory exists works with the standard VBA method:
...If Dir(Tempfilefolder, vbDirectory) <> vbNullString Then.....

To create a new folder, however, vba mkdir does not work.
I just need a normal folder, no data card behind it, just an empty folder with a specific name.

Is this really only possible with VB.net? Does this mean that I have to program the whole macro in VB.Net?

Re: Solidworks PDM API - add new folder

Posted: Fri Dec 01, 2023 2:01 pm
by AlexB
The PDM folder structure shown in Windows explorer is more of a "virtual" view of the file vault. The folder structure is actually dictated by the SQL database parent/child file relationships. So, due to the way this is set up, the new folder must be created with PDM API in order to update the database.

As for your question about a macro, this is possible to set up within Solidworks VBA the same way you normally create macros. The only additional thing you have to do is reference the PDM library (can't remember what it's called right now).

Note that using the API requires you to have PDM Professional.

Re: Solidworks PDM API - add new folder

Posted: Fri Dec 01, 2023 3:03 pm
by JSculley
Hansjoerg wrote: Fri Dec 01, 2023 12:24 pm Is it correct that the PDM API can only work with VB.Net and not with VBA?
That is not correct. You can use the PDM API from VBA. To create a folder, you can use CreateFolderPath or AddFolder. Both are methods of the IEdmFolder5 interface.

You can get a starting folder by using the RootFolder property of the EdmVault5 object.

Here's a simple example:

Code: Select all

Dim swApp As Object
Sub main()
    Dim vault As EdmVault5
    Dim rootFolder As IEdmFolder5
    Dim newFolder As IEdmFolder5
    Dim result As EdmMBoxResult
    Set vault = New EdmVault5
    vault.LoginAuto "_EPDM", 0
    Set rootFolder = vault.rootFolder
    Set newFolder = rootFolder.CreateFolderPath("\Engineering\Projects\123456-TEST PROJECT\6. Project Tracking\TEST", 0)
    result = vault.MsgBox(0, "Created folder " & newFolder.LocalPath)
    Set swApp = Application.SldWorks
End Sub

Re: Solidworks PDM API - add new folder

Posted: Tue Dec 05, 2023 12:49 pm
by AmenJlili
JSculley wrote: Fri Dec 01, 2023 3:03 pm That is not correct. You can use the PDM API from VBA. To create a folder, you can use CreateFolderPath or AddFolder. Both are methods of the IEdmFolder5 interface.

You can get a starting folder by using the RootFolder property of the EdmVault5 object.

Here's a simple example:

Code: Select all

Dim swApp As Object
Sub main()
    Dim vault As EdmVault5
    Dim rootFolder As IEdmFolder5
    Dim newFolder As IEdmFolder5
    Dim result As EdmMBoxResult
    Set vault = New EdmVault5
    vault.LoginAuto "_EPDM", 0
    Set rootFolder = vault.rootFolder
    Set newFolder = rootFolder.CreateFolderPath("\Engineering\Projects\123456-TEST PROJECT\6. Project Tracking\TEST", 0)
    result = vault.MsgBox(0, "Created folder " & newFolder.LocalPath)
    Set swApp = Application.SldWorks
End Sub

Code looks good. I'd add by saying to use the proper host window handle instead of 0. That will give you some issues in the future.

Amen Jlili,
cadoverflow.com