Setting Up an EPDM Dispatch Script to Rename SolidWorks Files


Dispatch is a very powerful EPDM tool which can be used for a variety of file specific operations. A very common need for the Vault would be an easy way to rename large amounts of SOLIDWORKS files based on certain data card values, and/or user inputs. This can be very easily accomplished with the use of a dispatch script. In the following example, I will explain the logic behind creating a working script to rename SOLIDWORKS files based off of a data card value. It is important to consider the manner in which you order your operations in the script. For each run of the script, it will execute each command from top to bottom. It is also very important to note that the script that is illustrated here will only work for SOLIDWORKS files. It is possible to modify this script for it to work on all file types. This will be explained later in the article. The following pictures illustrate a finished rename Dispatch script:

Edit action Set variables

  1. Here we have the method of activation and use.

    I have specifically assigned this script to run on "Menu command." This means that if I right click on a file or set of selected files, one of my menu options will always be to "Rename SOLIDWORKS Files."

    The advantage to this is that it will allow you to rename files whenever needed, as opposed to during a state transition, during a checkout/in operation, or file add, which are operations that have prerequisite functions that need to be completed in order to trigger the dispatch.

    The disadvantage, however, is that it will be available to everyone in the Vault. If you wish this type of operation to be completed by select individuals with certain permissions, I would suggest using the "During State Transition" condition, where you can assign "Permit" privileges to that, and in effect, to the dispatch script.

  2. Here we start out with a simple message prompt to the user which has a possibility of the user either pressing YES or NO. We are asking the user, only once, if all files are checked in prior to running this script. Based on the user's response, the value is saved in the runtime variable "d_runtimeansweryesno", shown in figure (10).

  3. This portion relates to the function detailed above in that we are implementing a conditional action based on the option chosen in figure (2).

    The IF statement compares the value saved into "d_runtimeansweryesno" and then compares it to a value we defined manually in the IF statement dialog. In this case, I manually typed "YES" into the IF statement dialog box. If the user selects "YES", it will be saved into the runtime variable, compared, and then sent to the label "YES" and continue on with the bottom portion of the script, figures (4) - (6).

    If the user selects "NO", then the script will prompt the message "Please check in all files before running this dispatch.", and then proceed to a second "IF condition which always jumps to the label "END", terminating the script.

  4. From here we start the portion of the script which allows for multiple files.

    As mentioned earlier, a Dispatch script has the potential to run for multiple files or for one file. If a user selects multiple files, a "For all documents" command is needed to tell the script to rerun the operation for ever file in the selection. It was placed in its current position specifically due to the fact that if we placed it at the very beginning of the script, above figure (2), then it would run the message prompts for every file that it selected, theoretically.

  5. Here is the main rename operation. We are defining the file in question with %PathToSelectedFile% as this will ensure the rename operation runs on only the file we selected. We are renaming it, in this case, with another dispatch variable "d_newfilename" which is shown in figure (9).

  6. Here we have the block end. Very simply, if you have a "For all documents", you need an "End for all documents" to finish the loop.

  7. Here we have the dispatch variable "d_extension".

    A rename operation with dispatch takes into account the entire filename including the extension, therefore we need to extract the extension of the original file name, in order to use it after the file is renamed with our intended value.

    SOLIDWORKS files always have a 6 character extension, we are saving the rightmost 7 characters, which includes the period separator.

    The value should now be saved into the "d_extension" variable.

  8. Here we have the dispatch variable "d_number" which is mapped to the value of a data card variable value for the specific configuration "@".

  9. Here we complete the operation of combining the saved Number variable value with whatever the file extension is, giving us a valid SOLIDWORKS file.

  10. Here is the runtime variable that was referenced in the first operation, Figure(1)  


As mentioned previously, this script as it is written will only work for SOLIDWORKS files. This is due to the simplicity in which the script was written, and the script can be modified to work for all file types by adding more complex logic to it. The level of complexity, however, is determined by what value you want applied to the filename, and how you want it applied.

Regardless, you would need to first determine a better way to find the extension of your file. The method listed in the pictures above shows logic of how to get the rightmost 7 characters of a file, but if this script was run on a ".docx" file, a ".dwg" file, or any other file that does not have 6 characters in the extension, it would produce improper results. In order to allow for the possibility of reading in multiple extensions, you would need to let "d_extension" equal the following value:

Mid(%NameOfSelectedFile%,Find(%NameOfSelectedFile%, .),7)

What this essentially does is locate the position of the "." in the filename, and then select that character plus any other characters to the right of it. The Find(%NameOfSelectedFile%, .) ends up reporting a numerical value of the position of the "." The rest of the command stipulates that any characters to the right of the specific position, including the character position specified will be saved. Notice how we still leave the "7" in the command. This is because it will look at up to 7 characters to save, if they exist. Since we know the largest extension in a vault is the SOLIDWORKS file, with 6 characters, we know it will pick up those. As far as ".docx" or ".dwg" files or anything containing less than 6 characters, it will simply ignore any empty characters after the extension. As a result, you could theoretically replace that "7" with "10000", and it would still return the same result.

The next step would be to allow cases for files that have different data cards. SOLIDWORKS files have a default "@" configuration, "DWG" files have a "Model" configuration, Office Documents have no configuration, etc... Due to the fact that a dispatch variable value requires a configuration specified(or an empty configuration value if there are no configurations for the file) you will need to create multiple dispatch variable for each potential case, and then add "IF" statements to the existing script, allowing the script to proceed appropriately for each specific case. Obviously, this could add considerable length to the existing script, so it would be important to test thoroughly once you feel the script has been completed.  


HawkRidge YouTube: SOLIDWORKS EPDM: Introduction to the EPDM Dispatch

HawkRidge YouTube: SOLIDWORKS EDPM: Dispatch Script Creation


If you have specific errors with your Dispatch Script please contact Hawk Ridge Technical Support to address those errors. 


Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.