Edit PDM Datacard Using VBA

In this guide, we’ll explore how to interact with SOLIDWORKS PDM datacard variables using VBA. This is particularly useful for automating tasks in PDM and SOLIDWORKS, streamlining your workflow.

For this demonstration, I’m using SOLIDWORKS 2023 and SOLIDWORKS PDM Professional 2023. The example will involve creating a VBA macro to access and modify datacard variables in a PDM vault.

Step 1: Creating a New Macro

To begin, open SOLIDWORKS and follow these steps:

  1. Go to Tools > Macro > New.
  2. Name the new macro DataCard.
  3. The Visual Basic for Applications (VBA) editor will open, allowing us to start coding.

This tutorial builds on previous work done on automating PDM through VBA. You can find our earlier tutorial on checking files into another vault on our Blue Byte YouTube channel.

Step 2: Setting References and Connecting to the Vault

Before we can manipulate PDM files, we need to set the references correctly and connect to the PDM vault.

  1. In the VBA editor, go to Tools > References.
  2. Look for PDMWorks Enterprise in the list of references (this is the PDM library) and select it.
  3. Click OK to save the reference.

Now, let’s define the essential variables:

Step 3: Connecting to the Vault

We’ll now establish a connection to the PDM vault and log in automatically.

Step 4: Getting the File and Folder

We need to retrieve the file from the vault using its file path. You can copy the full file path by right-clicking a file in File Explorer and selecting “Copy as Path”.

Step 5: Checking Out the File

Before modifying a data card variable, the file must be checked out.

Step 6: Accessing Datacard Variables

Now that the file is checked out, we can access the datacard variables. We’ll use the enumerator to set the variables.

This example sets the “Description” field on the data card of the selected file to “New Description”.

Step 7: Testing and Finalizing

Once you’ve run the macro, you should see the data card updated with the new value.

Summary:

In this tutorial, we demonstrated how to:

  • Set up a VBA macro in SOLIDWORKS.
  • Connect to a SOLIDWORKS PDM vault using the API.
  • Check out files and modify data card variables.

This is a powerful way to automate your PDM workflows, making file management more efficient.

If you found this tutorial helpful, subscribe to our YouTube channel and follow us on LinkedIn for more tips on automating SOLIDWORKS and PDM processes. Feel free to leave your questions in the comments, and I’d be happy to help!

Found an error or have suggestions? Send corrections via the comment section below. 👇

📝 Subscribe Now and join our community for goodies and more!