SolidWorks’ Enterprise PDM (EPDM) system contains what some might call a “poor man’s API” known as the Dispatch Tool. The Dispatch Tool allows non-programmers (those who don’t write formal code in Visual Studio.NET) to create basic programs, scripts, and functions within EPDM without having to learn a programming language. The tool is limited in functionality of course and is a procedural language, but it does provide a lot of ways to manipulate data inside EPDM. This article highlights the capabilities of the Dispatch Tool through an example that renames a file with the information contained on the file’s Data Card. Sample code for this example is provided.
To receive a copy of the code for this example (free of charge), please contact us and request the EPDM Dispatch Sample Code. The provided code file is already set up as an EPDM Administrative Action in the .ACN format. To use this code, the Dispatch Tool must be configured on the EPDM Administrative Tree under the Add-Ins menu. And to give credit where credit is due, this sample code is a derivative of a sample provided by SolidWorks.
Once you have the sample code, the .ACN file needs to be loaded into the system. Open EPDM Explorer View. Go to Tools -> Administrative Actions, and then click the Load button to browse and select your .ACN file. Once the .ACN is loaded, click the Edit button to review the code (shown in the screen shot below):
Here is a description of the key elements of the Edit Action window:
Action Name: Your “internal name” for the tool.
Description: A more detailed description of what the tool does.
Activation: You may choose when/how the action can be initiated. The Menu command option is checked for this example and we have given a descriptive name (this will be displayed to the end user).
Commands: This is the meat and potatoes of the code where all the good stuff happens. Below is a detailed list of each line in the code:
- For all documents: This lets the program know that this command is for documents only. It is not for BOMs, Items, or Folders. This also allows the user to multi-select several files and apply the command to them at one time.
- Jump: This line checks to make sure the variable that is used to rename the file has at least 1 number or character in it. You can change this value to whatever character length that you need, for example if your ERP system always needs an 8-digit number you could check to make sure that it is exactly 8 digits. If this check is not performed, then you risk have a file with no name and an extension only. If it passes this check, the code jumps to the “rename file” line, if not, it goes to the next line.
- OK Message Box: This will tell the user that the file was not renamed because there was no value in the data card variable “Number.”
- Jump: This line takes the command to the end of the loop “Skip Rename” when the file is skipped due to a blank Number field.
- Label: Rename File is where the commands are picked back up once all the checks are passed.
- Rename File: This line takes the path of the selected file, minus the extension, and renames it to a Dispatch Variable called “new_filename.” See below for a more detailed description of this variable.
- Label: Skip Rename
- End for all documents: Ends the command lines.
- Ok Message Box: Tells the user that the file has been renamed successfully.
The Dispatch variable used to rename the file is called “new_filename.” This variable takes the Data Card variable “Number,” puts it into a Dispatch variable called “DocNumber,” and combines it with the Dispatch variable “file_extension.” The proper EPDM names for these variables are %DocNumber% and %file_extension%.
Naturally, the Dispatch Tool can perform many useful actions, and you don’t need to be a programmer to take advantage of its automation capabilities. If you’re wondering what sorts of things are possible with the tool, or have a specific idea that you’d like to discuss, please contact us.