MX$0.00
0

Replace a Dispatch PDF Cleanup With a PDMShell Task on a Task Host

Move a Dispatch action that deletes old PDF revisions on a network drive to a PDMShell task on a task host, so only a service account can write to the folder.
PDMShell Script page of the PDM task with the cleanup script and runtask line
Picture of Amen Jlili

Amen Jlili

Amen Jlili is the founder and technical director of Blue Byte Systems Inc., a software company in Vancouver, Canada, specializing in automating SOLIDWORKS and PDM.

A common SOLIDWORKS PDM Dispatch action deletes the previous revision of a PDF on a network drive when a drawing is released. It works, but Dispatch runs on the computer of the person who changes the state, under that person’s Windows account. Every user who releases a file needs write access to the network folder, so every user can also delete or overwrite the released PDFs by hand.

Moving the job to a PDM task fixes that. The task runs on a task host under one service account, so the folder can be locked down to that account and stay read-only for everyone else. In this article I set up that task with PDMShell, step by step, with current screenshots of SOLIDWORKS PDM Administration and PDMShell. One script replaces the whole set of Dispatch actions you may have for different file types and workflows.

How it works

  1. A user releases a drawing or an Office document.
  2. The release transition starts the Publish Released PDF task on the task host.
  3. PDMShell deletes the older PDFs of that document from the network folder.
  4. PDMShell runs your existing Create PDF task with runtask, which prints the PDF for the new revision into the same folder.

Users never write to the network folder. Only the service account on the task host does.

Before you start: licensing

PDMShell has two kinds of license. A computer license activates standalone PDMShell on one computer, which is where you write and test scripts. Vault licenses go into the vault license pool and cover scripts and tasks that run through the PDMShell add-in in SOLIDWORKS PDM. A task host running a PDMShell task takes its seat from the vault license pool.

Open PDMShell, select Settings, then License. Under Vault licenses, pick the vault and choose Manage. Managing the pool needs the Edit add-ins permission in that vault.

PDMShell Settings License page showing the computer license and the vault license pool
PDMShell Settings, License page

In License center, paste your key under Add license keys, choose Add keys, then Save changes. The key shows as Active for the vault.

PDMShell License center for the vault license pool
License center for the vault license pool

The PDMShell add-in must also be in the vault. If it is not there yet, open Settings, then Vault add-in, and choose Install / update vault add-in. This affects all vault users and does not use a license on its own.

Vault add-in page in PDMShell Settings
Installing the PDMShell add-in in a vault

If you are evaluating, the free PDMShell trial covers everything in this article, and I convert your existing Dispatch actions as part of the trial.

Step 1: Lock down the network folder

On the file server, give the service account Modify permission on the PDF folder, for example \\fileserver\Engineering\Released PDFs. Give everyone else Read only, and remove Modify from any engineering group that had it for Dispatch.

Step 2: Prepare the task host

Pick a computer that stays on and sign in to Windows with the service account. Install the SOLIDWORKS PDM client, PDMShell, and SOLIDWORKS if Create PDF prints SOLIDWORKS drawings. A task runs in the Windows session of the account that is signed in on the task host, so this account is the one that reads and writes the network folder.

Then open Task Host Configuration from the SOLIDWORKS PDM icon in the Windows notification area, select the vault, and check Permit for PDMShell and for the add-in your Create PDF task uses, such as the SOLIDWORKS Task Add-in or PDMPublisher. A task host only runs the add-ins permitted here. Choose OK.

Task Host Configuration in the SOLIDWORKS PDM notification area menu
Task Host Configuration in the SOLIDWORKS PDM menu
Task Host Configuration with PDMShell permitted for the vault
PDMShell permitted on the task host

Step 3: Check the Create PDF task

The script prints the PDF with your existing Create PDF task, whether it is a SOLIDWORKS Convert task or a PDMPublisher task. Open it in Administration and on its output page point the output folder to the same network folder. Use a file name format that starts with the document name, then an underscore, then the revision, for example 1001-0042_B.pdf. The cleanup in the script relies on that naming. Set Create PDF to run on the same task host.

Step 4: Create the PDMShell task

In SOLIDWORKS PDM Administration, expand the vault, right-click Tasks and choose New Task.

Tasks node in SOLIDWORKS PDM Administration
Tasks in SOLIDWORKS PDM Administration
New Task command on the Tasks node in SOLIDWORKS PDM Administration
New Task on the Tasks node

Name the task Publish Released PDF. On the Add-in page, select PDMShell.

Add-in page of a new PDM task with PDMShell selected
Add-in page with PDMShell selected

Execute task as user sets the PDM login the task uses. Execute as logged in user uses the PDM account signed in on the task host. You can also pick a dedicated PDM user. Either way, access to the network folder comes from the Windows account on the task host, not from this setting.

On Execution Method, check the task host computer. With Let the system choose the computers to execute the task, PDM sends the task to one of the checked computers.

Execution Method page of the PDM task with the task host computer checked
Execution Method with the task host checked

Step 5: Add the script

Open the PDMShell Script page and paste this script. Change the folder on the second line to your own.

# Folder that holds the published PDFs. Only the service account can write here.
setglobal -name PdfFolder -value "\\fileserver\Engineering\Released PDFs"
setglobal -name BaseName -value "$fileNameWithoutExtension"

# 1. Remove every older PDF of this document
delete -fsSearch "${global.BaseName}_*.pdf" -fsSearchDir "${global.PdfFolder}" -destroy

# 2. Print the PDF for the current revision with the Create PDF task
runtask -filePath "$filePath" -taskName "Create PDF"

Let Claude or ChatGPT write it

You do not have to write this script by hand. The PDMShell commands are documented online, so Claude or ChatGPT can write a script like this from a plain description of what the task must do. Paste the result into the PDMShell Script page and test it before you use it.

Example prompt for Claude or ChatGPT
You
Write a PDMShell script for a PDMShell task in SOLIDWORKS PDM. For the file the task runs on, delete every PDF in \\fileserver\Engineering\Released PDFs whose name starts with the file name and an underscore, then run the Create PDF task on that file.
AI assistant
Here is a script for the PDMShell Script page of your task:
# Folder that holds the published PDFs. Only the service account can write here.
setglobal -name PdfFolder -value "\\fileserver\Engineering\Released PDFs"
setglobal -name BaseName -value "$fileNameWithoutExtension"
 
# 1. Remove every older PDF of this document
delete -fsSearch "${global.BaseName}_*.pdf" -fsSearchDir "${global.PdfFolder}" -destroy
 
# 2. Print the PDF for the current revision with the Create PDF task
runtask -filePath "$filePath" -taskName "Create PDF"
Check Do not use optimized script execution on the task so each file runs the whole script before the next one starts. Test it with Test With File before you add it to the workflow.

PDMShell also has AI built in. Choose AI in the PDMShell window to connect ChatGPT, Claude or a local Ollama model, see AI in PDMShell. With the PDMShell MCP server, Claude Desktop can read the exact syntax of every PDMShell command before it writes the script, which avoids made-up parameters. Either way, review the script and run Test With File on a test drawing first.

PDMShell Script page of the PDM task with the cleanup script and runtask line
PDMShell Script page with the cleanup and runtask lines

Here is what each line does:

  • setglobal -name PdfFolder stores the network folder once, so you only change the path in one place.
  • setglobal -name BaseName stores the name of the file the task is running on, without its extension. For 1001-0042.slddrw it is 1001-0042.
  • delete with -fsSearch looks in the network folder for every PDF that starts with that name and an underscore, such as 1001-0042_A.pdf and 1001-0042_B.pdf, and deletes them. -destroy deletes them permanently instead of sending them to the Recycle Bin.
  • runtask runs the Create PDF task on the same file. Create PDF then prints the PDF for the current revision into the network folder.

Under Affected documents, set File extensions to the types your Dispatch actions covered, for example slddrw;docx;xlsx. Check Do not use optimized script execution so the whole script finishes for one file before the next file starts.

One thing to watch: the pattern matches every PDF whose name starts with the document name and an underscore. If one document number can be the start of another one followed by an underscore, use a more specific pattern.

Step 6: Error handling and permissions

Expand Error handling. With Stop script after a non-ignored error off, the script still reaches the runtask line if the delete reports a problem, and the task ends as Failed so you see it in the Task List. Turn it on if you would rather stop at the first error.

Error handling options on the PDMShell Script page
Error handling options

On Permissions, check the users or groups allowed to start the task. When a workflow transition starts the task, include everyone who can release files. Choose OK to save the task.

Permissions page of the PDM task
Task permissions

Step 7: Start the task on release

Open the workflow and double-click the transition that releases files, Release Documents in this example. On the Actions tab, choose Add Action. In Transition Action, set Type to Execute task, check Run for files, and under Select task to execute pick Publish Released PDF. Choose OK twice. Repeat this for every transition into Released, such as No Approval Required, and for every workflow your Dispatch actions covered. Then remove the old Dispatch actions from those transitions.

Release Documents transition in a SOLIDWORKS PDM workflow
Release transitions in the workflow
Actions tab of the Release Documents transition properties in SOLIDWORKS PDM
Actions tab of the transition. Choose Add Action.
Transition Action dialog with the Execute task type
Set Type to Execute task, check Run for files, then select Publish Released PDF under Select task to execute.

Step 8: Test it

On the PDMShell Script page, choose Test With File and pick a test drawing. The test runs the real script, so use a file and a folder you do not mind changing. Then release a test drawing and follow the task under Tasks, Task List. The older PDFs disappear from the network folder and the PDF for the new revision appears.

Get your Dispatch actions converted

If your vault has Dispatch actions like this one, send them to me. I convert them to a single PDMShell script as part of your free PDMShell trial. See Dispatch to PDMShell for how it works.

Need this adapted to your workflow?

We build custom SOLIDWORKS macros, add-ins and PDM automation.

Picture of Amen Jlili

Amen Jlili

Amen Jlili is the founder and technical director of Blue Byte Systems Inc., a software company in Vancouver, Canada, specializing in automating SOLIDWORKS and PDM.

Leave a Comment

0
0
Your Cart
Your cart is emptyReturn to Shop