All Resources
Code SnippetSolidWorks API2026-03-19

Automate SolidWorks Pack and Go

Programmatically package a SolidWorks assembly with all referenced files. Supports including drawings, flattening folders, adding prefix/suffix, and auto-incrementing serial numbers.

csharp
using SolidWorks.Interop.sldworks;

public string PerformPackAndGo(ModelDoc2 assemblyDoc, string destPath,
    string prefix)
{
    var swExt = assemblyDoc.Extension;
    var swPackAndGo = swExt.GetPackAndGo();

    swPackAndGo.IncludeSuppressed = false;
    swPackAndGo.IncludeDrawings = true;
    swPackAndGo.FlattenToSingleFolder = true;

    Directory.CreateDirectory(destPath);
    swPackAndGo.SetSaveToName(true, destPath);

    // Auto-increment serial number
    int serial = GetNextSerial(destPath, prefix);
    swPackAndGo.AddPrefix = $"{prefix}-{serial}-";

    swExt.SavePackAndGo(swPackAndGo);
    return destPath;
}

private int GetNextSerial(string folder, string prefix)
{
    if (!Directory.Exists(folder)) return 1;

    var files = Directory.GetFiles(folder, $"{prefix}-*-*");
    int maxSerial = 0;

    string escaped = Regex.Escape(prefix);
    string pattern = $@"^{escaped}-(\d+)-";

    foreach (var file in files)
    {
        string name = Path.GetFileNameWithoutExtension(file);
        var match = Regex.Match(name, pattern);
        if (match.Success && int.TryParse(
            match.Groups[1].Value, out int serial))
        {
            maxSerial = Math.Max(maxSerial, serial);
        }
    }

    return maxSerial + 1;
}

How It Works

Pack and Go collects an assembly and ALL its referenced files (parts, sub-assemblies, drawings) into a single destination folder. The API follows a three-step lifecycle:

  1. Get: Extension.GetPackAndGo() creates a PackAndGo object pre-loaded with all references
  2. Configure: Set properties like IncludeDrawings, FlattenToSingleFolder, AddPrefix
  3. Save: Extension.SavePackAndGo(swPackAndGo) copies all files to the destination

Key Properties

PropertyDefaultRecommended
IncludeSuppressedtruefalse — suppressed components are usually not needed
IncludeDrawingsfalsetrue — you almost always want the drawings
FlattenToSingleFolderfalsetrue — avoids complex nested folder structures
IncludeToolboxComponentstruefalse — toolbox parts are shared, don't duplicate

Serial Numbering

The GetNextSerial helper scans the destination folder for existing files matching the prefix pattern, extracts the highest serial number using regex, and increments it. This ensures each Pack and Go operation creates uniquely named files.

For example, if the folder contains ORD001-1-Panel.SLDASM and ORD001-2-Panel.SLDASM, the next serial will be 3.

When to Use

  • Archiving revisions: Snapshot an assembly at a specific point in time
  • Job-specific copies: Create a copy for each manufacturing order
  • Distributing to vendors: Package everything needed to open the assembly
  • Pre-production freeze: Lock down the design before cutting material

Important Limitation

Pack and Go does NOT update internal references in the copied files. The copied assembly still references the original file paths. This makes Pack and Go suitable for:

  • Archival: You want a frozen snapshot, not a working copy
  • Distribution: The recipient will open from the flattened folder

If you need a working copy with updated references, use Save As with the UpdateReferences option instead.

SolidWorks APIC#Pack and GoFile Management