Solidworks PDM API - add new folder

Programming and macros
User avatar
Hansjoerg
Posts: 115
Joined: Thu Apr 01, 2021 4:17 pm
Answers: 3
x 71
x 60

Solidworks PDM API - add new folder

Unread post 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?
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
User avatar
AlexB
Posts: 508
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 29
x 274
x 462

Re: Solidworks PDM API - add new folder

Unread post 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.
User avatar
JSculley
Posts: 648
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 888

Re: Solidworks PDM API - add new folder

Unread post 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
AmenJlili
Posts: 8
Joined: Thu Nov 30, 2023 5:17 pm
Answers: 0
x 6

Re: Solidworks PDM API - add new folder

Unread post 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
Post Reply