RUNSWMACRO Command Documentation
DESCRIPTION:
The RunSWMacro command allows you to execute a SOLIDWORKS macro on a specific file or on multiple files found via search in the PDM vault. This is useful for automating repetitive tasks or applying custom logic to many files.
SYNTAX:
runswmacro -filePath -search -recursive -list -skip -count -timeout
PARAMETERS:
The command requires the following parameters:
filePath: Path to the SOLIDWORKS macro file (.swpor.dll). This is required and the file needs to cached in PDM.search: Search query to find files to run the macro on.recursive: If set, search will include subfolders.list: csv file path of filepaths without a column header.skip: Skips the specified number of items. Only valid withlist.count: Only processes the specified number of items. Only valid withlist.timeout: Macro timeout in seconds (for both the macro to execute and for SOLIDWORKS to start too)
What version of SOLIDWORKS will PDMShell use?
PDMShell will use the latest SOLIDWORKS version installed on your system by checking the Windows Registry at:
HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks
Note
If you have multiple SOLIDWORKS versions installed, PDMShell will automatically select the most recent version found in the registry.
List Example
C:\TestVault\part1.sldprt
C:\TestVault\assembly2.sldasm
C:\TestVault\drawing3.slddrw
C:\TestVault\bracket4.sldprt
SWP Macro
Warning
Please read the remarks below to properly call your macro.
- The macro procedure name must be called
main. - The macro module name must be called the file name of the macro appended by
1. Example: If the macro calledprint.swpthe module name must be calledprint1.
DLL Macro
Warning
Please read the requirements below to properly create your DLL macro.
Requirements
- The macro class must implement the
IPDMShellSOLIDWORKSMacrointerface - The class must be decorated with the
PDMShellMacroattribute - The interface can be found in the NuGet package
BlueByte.PDMShell.SOLIDWORKSMacroon nuget.org
Required NuGet Package Versions
Important
Your project must use these specific versions of the NuGet packages:
<PackageReference Include="BlueByte.PDMShell.SOLIDWORKSMacro" Version="1.0.0" />
<PackageReference Include="BlueByte.SOLIDWORKS.Interops" Version="2019.0.0" />
<PackageReference Include="BlueByte.SOLIDWORKS.PDMProfessional.Interops" Version="2024.5.50" />
Install using Package Manager Console:
Install-Package BlueByte.PDMShell.SOLIDWORKSMacro -Version 1.0.0
Install-Package BlueByte.SOLIDWORKS.Interops -Version 2019.0.0
Install-Package BlueByte.SOLIDWORKS.PDMProfessional.Interops -Version 2024.5.50
Note
Using different versions may result in compatibility issues or runtime errors. These specific versions are tested and guaranteed to work with PDMShell.
Example Implementation
using PDMShellSOLIDWORKSMacro;
using SolidWorks.Interop.sldworks;
using EPDM.Interop.epdm;
[PDMShellMacro]
public class MyMacro : IPDMShellSOLIDWORKSMacro
{
public bool Execute(
SldWorks swApp,
IEdmFile5 pdmFileObject,
IEdmFolder5 pdmFolderObject,
int handle,
string progress,
IPDMCmdLineCallback callback,
out string error)
{
error = string.Empty;
// Update progress using the callback
callback.AppendMessage("Starting macro execution...");
// Your macro implementation here
callback.AppendMessage($"Processing file: {pdmFileObject.Name}");
// Report completion
callback.AppendMessage("Macro execution completed successfully");
return true;
}
}
Note
Use the callback.AppendMessage() method to provide progress updates and status messages during macro execution. These messages will be displayed in the PDMShell output.
Running the Macro
# Run the DLL macro on all parts in the current directory
runswmacro -filePath "Macros/MyMacro.dll" -search "%.sldprt" -timeout 12000
Note
The DLL must be built against .NET Framework 4.7.2 or higher
EXAMPLE:
# run batch export macro on all part in the current directory
runswmacro -filePath "Macros/BatchExport.swp" -search "%.sldprt"