Rebuild SOLIDWORKS Document
This script checks out the selected SOLIDWORKS document, changes the working directory to the file folder, runs a rebuild macro, and checks the file back into SOLIDWORKS PDM.
Tip
You can download this script directly from the PDMShell Script Library. Open PDMShell, open the Script Library, choose Rebuild SOLIDWORKS Document, and load the script into the active session.
Script
Download the PDMShell script and download the rebuild macro.
checkout -filePath "$localPath"
cd -directory "$folderPath"
runswmacro -filePath "$tempFolder\RebuildMacro.swb" -search "Name=$fileName" -timeout 500
checkin -filePath "$localPath"
What it does
- Checks out the selected file from SOLIDWORKS PDM.
- Changes the PDMShell working directory to the selected file folder.
- Runs a SOLIDWORKS macro against the selected file.
- Rebuilds the SOLIDWORKS document.
- Checks the file back into PDM.
Requirements
- SOLIDWORKS must be installed on the machine running PDMShell.
- The user must have permission to check out and check in the file.
- The file should be a supported SOLIDWORKS document, such as
.sldprt,.sldasm, or.slddrw. - For manual setup, save the macro as
RebuildMacro.swbin your Windows temporary folder (%TEMP%). The script refers to this location as$tempFolder\RebuildMacro.swb. Keep the.swbextension, not.swpor.txt.
Macro code
This is the same macro supplied by the Script Library. It rebuilds, saves, and closes the active SOLIDWORKS document. If the download opens as text in your browser, use Save link as to save RebuildMacro.swb.
Test on a backed-up document first. This existing macro does not report rebuild or save failures to the script; do not treat the later check-in as confirmation that the rebuild succeeded.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
Exit Sub
End If
Dim modelTitle As String
modelTitle = swModel.GetTitle
swModel.ForceRebuild3 True
Dim errors As Long
Dim warnings As Long
swModel.Save3 swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings
swApp.CloseDoc modelTitle
End Sub
Placeholders used
| Placeholder | Description |
|---|---|
$localPath |
Full local path of the selected file |
$folderPath |
Local folder path of the selected file |
$fileName |
File name of the selected file |
$tempFolder |
Temporary folder in your Windows session |