CA$0.00
0

How to Rebuild SOLIDWORKS Files in SOLIDWORKS PDM with PDMShell

Rebuild SOLIDWORKS parts, assemblies and drawings stored in SOLIDWORKS PDM from the right-click menu: one PDMShell script checks out, rebuilds, saves and checks in.
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.

To rebuild a SOLIDWORKS file stored in SOLIDWORKS PDM without opening it by hand, right-click it and run the PDMShell Rebuild SOLIDWORKS Document script. It checks the file out, opens it in SOLIDWORKS, forces a full rebuild, saves it and checks it back in. Select a hundred files and it does the same for each one.

Rebuilding sounds trivial until you have to do it to an entire project. Maybe a template changed, a toolbox part was updated, or files were created in an older SOLIDWORKS version and still carry the rebuild flag. Opening, rebuilding, saving and checking in each file by hand is the kind of job that takes an afternoon and teaches nobody anything. This four line script takes it off your plate.

When a bulk rebuild is worth it

  • After a SOLIDWORKS upgrade, to clear the rebuild needed flag before files are released.
  • After updating a referenced part, so the assemblies and drawings that use it show current geometry and mass properties.
  • Before a release or a customer delivery, so every exported PDF and STEP comes from a freshly rebuilt model.
  • After changing custom properties that feed equations or linked notes.

The complete script

You can load this script from the PDMShell Script Library inside the app, or copy it from the Rebuild SOLIDWORKS Document recipe in the PDMShell documentation.

checkout -filePath "$localPath"

cd -directory "$folderPath"

runswmacro -filePath "$tempFolder\RebuildMacro.swb" -search "Name=$fileName" -timeout 500

checkin -filePath "$localPath"

How it works, line by line

Line 1: check the file out

checkout -filePath "$localPath"

$localPath is the full local path of the file you right-clicked. The file has to be checked out before SOLIDWORKS is allowed to save it back to the vault.

Line 2: move to the file folder

cd -directory "$folderPath"

This changes the PDMShell working directory to the folder the file lives in, so the search on the next line only looks there.

Line 3: run the rebuild macro

runswmacro -filePath "$tempFolder\RebuildMacro.swb" -search "Name=$fileName" -timeout 500

runswmacro starts SOLIDWORKS, opens every file that matches the search, which here is the selected file by name, and runs the macro on it. The timeout of 500 seconds gives large assemblies enough time to open and rebuild.

Line 4: check the file back in

checkin -filePath "$localPath"

The rebuilt and saved file goes back into the vault as a new version.

The rebuild macro

The script expects a macro called RebuildMacro.swb in your Windows temporary folder. A .swb file is a plain text SOLIDWORKS macro, so you can create it in Notepad. Save the following as RebuildMacro.swb in %TEMP%:

Dim swApp As Object

Sub main()

    Set swApp = Application.SldWorks

    Dim swModel As Object
    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then Exit Sub

    Dim errors As Long
    Dim warnings As Long

    ' False rebuilds the whole model, not only the top level
    swModel.ForceRebuild3 False

    ' 1 = silent save
    swModel.Save3 1, errors, warnings

End Sub

ForceRebuild3 with False rebuilds every feature and component, which is the same as pressing Ctrl+Q in SOLIDWORKS. Save3 with option 1 saves without showing any dialogs, so the script never stops to wait for a click.

Run it from the right-click menu

Save the script as a vault script and give it a menu name such as Rebuild in SOLIDWORKS. Our guide on adding a right-click command to SOLIDWORKS PDM with a PDMShell vault script walks through the vault script settings step by step. Once it is in place, select one file or many in File Explorer and choose the command. Each selected file is checked out, rebuilt, saved and checked in.

If you run the script from the PDMShell add-in, add quit -silent as the last line so the background PDMShell session closes when it is done.

Requirements

  • SOLIDWORKS installed on the computer running PDMShell.
  • Check out and check in permission on the selected files.
  • Supported SOLIDWORKS documents: parts, assemblies and drawings.
  • RebuildMacro.swb saved in your Windows temporary folder.

Frequently asked questions

Does it rebuild every configuration?

The macro rebuilds the configuration the file opens in. To rebuild all configurations, loop through them in the macro with ShowConfiguration2 and call ForceRebuild3 for each one before saving.

What if a file is already checked out by someone else?

The checkout fails and the file is skipped. Nothing is saved over another person’s work.

Is there a way to rebuild without writing a macro?

PDMShell Premium includes a rebuild command that force rebuilds and saves cached SOLIDWORKS files that you have checked out. The macro version above works with the free edition.

Need a custom rebuild workflow?

If you want rebuilds to run automatically on a workflow transition, or across a whole vault overnight, contact us. We build PDMShell automation for SOLIDWORKS PDM teams every week.

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