Skip to content

About

SolidWorks add-in and macros for EasyPDM, a small self-hosted PDM

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

EasyPDM for SolidWorks

English | Polski | Deutsch

Buy Me A Coffee

The SolidWorks side of EasyPDM, a small, self-hosted PDM: an add-in with an EasyPDM tab in the CommandManager (Addin/), the Upload and Download macros it runs, and the EasyPDM drawing sheet. Until 0.9 they lived in the EasyPDM repository, in EasyPDM.SolidWorks/; their history came along.

The EasyPDM tab in SOLIDWORKS

A part with the EasyPDM document panel in the Task Pane

Installing the add-in: download the latest release (the zip and both .swp macros), unpack them into one folder that stays, run install.cmd as administrator and start SOLIDWORKS — details in Addin/README.md. Step by step, with screenshots of where everything is: the wiki.

The macros

Two .bas macros, each fully self-contained (separate file, separate VBA module, no dependencies between them beyond a shared spot in the Windows registry for the login session):

  • EasyPDMUpload.bas — sends the active SolidWorks document to EasyPDM. The choice of project/new-vs-existing/duplicate/item properties happens in the browser (the same pattern as the FreeCAD add-on), with one exception — see "Differences from the FreeCAD macros" below.
  • EasyPDMDownload.bas — fetches a Part/Assembly from EasyPDM (together with all of the assembly's components) and opens it in SolidWorks; the choice of WHICH item also happens in the browser.

Status

Live-verified end-to-end on real SolidWorks 2026, across several rounds of testing and bug-fixing (starting 2026-08-20, most recently 2026-08-27): login, the browser ticket flow (new item/duplicate/attach to existing), file upload/registration, STEP/PDF attachment export, automatic assembly-tree detection with per-component browser tickets, and EasyPDMDownload.bas's recursive component download — all confirmed working against a live server, not just reviewed statically (there is still no VBA compiler in the environment these files are edited from, so every fix here came from the user reproducing an issue live and pasting the macro's own log, not from a build step). See "History of fixed issues" below for the specific bugs this process found.

A few narrow, low-traffic code paths remain genuinely untested in practice (marked UNVERIFIED inline in the source) — see "Known risks" below.

Run again on SOLIDWORKS 2024 SP5 on 2026-11-17, through the add-in: Upload, Download, the browser sign-in, the version stamp and the language following SOLIDWORKS.

Differences from the FreeCAD add-on

These are counterparts, not a 1:1 port — VBA has no built-in JSON and no dialog windows without separate binary files (SolidWorks/VBA UserForm), so several things are solved differently:

  • JSON: its own, minimal parser/builder inside the macro itself (duplicated in both files, not shared — VBA has no reliable way to import one module from another) — sufficient for the response shapes of this specific API, not general-purpose.
  • No UserForm — instead of FreeCAD's Qt forms, all native windows are plain InputBox/MsgBox (UserForm is a separate binary file, it can't be bundled into a single .bas imported through "File → Import File..."). The login password can't be masked with asterisks using a plain InputBox. Waiting for the browser (see below) shows progress in SolidWorks' status bar instead of in a window with a Cancel button — Escape is the only available cancel gesture.
  • Choice of project/new-vs-existing/duplicate/item properties in the browser — the same ticket+GET /api/auth/browser-login+"pending request from a CAD macro" popup pattern as the FreeCAD add-on, with one deliberate exception: if the document is ALREADY linked to a PDM item (see the point below), the macro does NOT open the browser at all — it asks locally (native MsgBox) for consent to a new revision, plus whether to export STEP and/or PDF (see below), exactly as before this change. SolidWorks then knows the item with 100% certainty, so the browser wouldn't add anything here; FreeCAD always goes to the browser (or, since a recent change, a native confirmation first when a label match is found) because it has no equally reliable local mechanism.
  • Recognizing an "already sent" document (EasyPDMUpload.bas): NOT through a label/file name (SolidWorks has no equivalent of FreeCAD's free-form label) — through the document's Custom Properties (EasyPDM_ItemId, EasyPDM_ItemNumber), saved into the file itself after a successful upload. This is actually a more durable approach than in FreeCAD — it also works in a NEW SolidWorks session, and is also used for EVERY assembly component individually (see "assembly tree detection" below), not just for the main document.
  • New assembly components go through the browser too, one at a time — each not-yet-linked component discovered while walking the tree gets its own form (leaves first, same New item/Duplicate/Attach to existing choice as the top-level document, but with no project or parent to pick: a component follows the SolidWorks tree and joins the top-level item's project when it is attached). The form appears in the browser tab that is already open — no new tab and no click per component. Only if no browser takes the request within a few seconds does the macro fall back to a "click OK to continue" MsgBox and a new tab, since only one browser tab per macro run can reliably grab Windows' foreground focus (check the taskbar if a step seems to hang).
  • STEP and PDF export are both optional everywhere — a checkbox for each in the ticket-driven browser paths (new item/duplicate/attach to existing, at both the top-level document and per assembly component), or two native Yes/No prompts (ExportStepPrompt/ExportPdfPrompt, STEP defaulting to Yes, PDF to No) on the browser-less "already linked" path. PDF export uses SolidWorks' own "Save As PDF", tagged as the "pdf" attachment role, separate from and independent of the STEP attachment.

What EasyPDMUpload.bas does

  1. Login — on first run (or when the saved login has expired or been revoked) it signs in through the browser: it asks for the server address, opens EasyPDM with a code, and after you click Allow there and OK in SolidWorks it has a macro token of its own; the password never passes through SolidWorks. Only an EasyPDM server older than 0.9, which has no browser sign-in, makes it ask for a username and password instead. The token is saved in the Windows registry (HKEY_CURRENT_USER\Software\VB and VBA Program Settings\EasyPDM) via the built-in SaveSetting/GetSetting — subsequent runs (also after restarting SolidWorks, also from EasyPDMDownload.bas and the add-in — the login is shared) don't ask to log in again while the token is valid (a year, unless revoked in Settings → Users).
  2. Saves the active document, if it hasn't been saved yet (SolidWorks' standard "Save As" window).
  3. If the active document is an Assembly: resolves any Lightweight components first (ResolveAllLightWeightComponents, called directly on the assembly model — calling it through .Extension instead silently no-ops and was a real bug caught in testing: GetModelDoc2() returns Nothing for a still-Lightweight component, making it indistinguishable from "component not found" until resolved), then detects the component tree (IAssemblyDoc.GetComponents, recursively). A pre-walk summary MsgBox lists every discovered component, flagging already-linked ones with their target PDM item number and filename — a deliberate guard, since SolidWorks' own Save-As silently copies Custom Properties, which can make a genuinely new part falsely "recognize" itself as an existing item if you're not paying attention to this summary. If confirmed, it walks leaves first (this document last); for each NOT-yet-linked component it opens its own browser ticket (same New item/Duplicate/ Attach to existing choice as the top-level document, shown in the already-open browser tab — see "Differences from the FreeCAD add-on"). Newly created components get their own STEP/PDF export (per that component's own checkbox choice in the browser) and EasyPDM_ItemId entry, and are automatically attached under their parent in the BOM structure. Already-linked components are attached to the BOM with the calculated quantity. Those "In work" are updated on "Yes" in the "Assembly detected" question: each one's CAD file replaces the same revision in the PDM, and two short questions decide whether STEP and PDF are exported again. The main assembly in work is included, so it is not asked about separately. A failed update gets a warning and a red cross in the progress panel, and the run goes on. Components "Under review" or "Released" are never sent: the "Assembly detected" question marks them, and after "Yes" one information window lists them. Components removed from the assembly since the last upload are flagged too — for every parent (the top-level document and every sub-assembly), before attaching its current local children the macro checks whether PDM still has a BOM relation to a child no longer present locally, and asks natively for confirmation before removing that link (the items themselves are never deleted, only their attachment under this specific parent). Confirming also unassigns the removed child from ANY project instead of dumping it into the current project's root — it stays fully visible and findable via the global "whole database" search, it just stops cluttering the structure of a project it no longer has anything to do with (the same mechanism the web application's own "Remove from structure" uses).
  4. Checks the main document's Custom Properties:
    • Already linked (has a saved EasyPDM_ItemId) — asks locally for consent to attach the current version as a new revision, without opening the browser (see "Differences from the FreeCAD add-on"), followed by two more native Yes/No prompts for STEP export (default Yes) and PDF export (default No).
    • Not yet linked — opens the system browser (already logged in, token→cookie bridge) to the "pending request from a CAD macro" popup, with three options to choose THERE: New item (project, optionally a parent, type, name — for Parts additionally the kind and its dependent fields: Manufactured → Material; Purchased → Manufacturer/Series-Type/Subtype/Order numbers/Mass; Standard part → Material/Norm; Client's → Client + Name 2 (only once a Client is picked); an Assembly has kinds of its own (Manufactured; Purchased → Manufacturer/Series-Type/Subtype; Client's → Client + Name 2) plus an always-optional Mass — plus STEP and PDF export checkboxes), Duplicate (points to an existing item, copies its properties to a new one, no files) or Attach to existing (search across the whole database + the same STEP/PDF checkboxes). The macro waits (polls every ~2s, 10-minute limit, Escape cancels, progress shown in SolidWorks' status bar) and continues automatically once the choice is confirmed in the browser.
    • Existing item with "Released" status (both paths above): asks for consent to a new revision and an optional comment — exactly the same mechanism as in the web application, the only decision deliberately staying local even on the browser path.
    • Existing item with "Under review" status: attaching is instead hard blocked with a native error message — the macro does NOT silently flip the status back to "In progress" and upload anyway (that was a real, fixed bug: someone reviewing the item could have it silently reset out from under them by a re-upload). Whoever is reviewing needs to move the item out of "Under review" in the web application first.
  5. Saves the document under the PDM name number (name).REVISION.extension (the same convention as in the web application and the FreeCAD add-on) in the target folder Upload asked for, and copies that file into the PDM. The file it was saved under before stays on disk, neither moved nor deleted. Before that save, a part or assembly gets a fresh version stamp, the custom property EasyPDM_ContentVersion, sent along with the file: it lets EasyPDM tell this exact upload from an older or a locally changed copy, also after SolidWorks saves the file again unchanged, which is what the add-in's outdated-component check relies on. If the PDM storage is visible from this machine (GET /api/config), the copy goes to the shared storage/components/ and is registered without re-uploading over HTTP; if not (typical when SolidWorks and the EasyPDM service run as different Windows users — the storage is under C:\ProgramData\..., which a regular user usually has no write access to), a plain HTTP upload (fallback, which keeps earlier revisions too and uses WinHttp.WinHttpRequest.5.1 specifically for this call — see "History of fixed issues" below) — this is not a bug, just a security measure working correctly. This fallback path also checks for and deletes any existing "cad"-role attachment with the exact same filename before uploading, so re-saving at the same revision letter doesn't accumulate duplicate attachments.
  6. When STEP/PDF export is enabled (checkbox in the browser, or the native prompts on the browser-less path — see point 4): exports the visible geometry to a temporary .step/.pdf file (IModelDocExtension.SaveAs) and uploads it as an attachment with the role "step"/"pdf", replacing the previous attachment of that same role — feeds the persistent 3D preview (STEP) in the web application. An export error (e.g. no visible geometry) does NOT abort the rest of the operation.
  7. Saves EasyPDM_ItemId/EasyPDM_ItemNumber into the document's Custom Properties. The report of the run (what went up, what failed) lands in the web app's notifications rather than in a window in SolidWorks.

What EasyPDMDownload.bas does

  1. Login — as above (session shared with EasyPDMUpload.bas).
  2. Choosing the item to download happens in the browser — the same "pending request from a CAD macro" popup as when uploading, except right away with just the search (no New/Duplicate choice, irrelevant when downloading). The macro waits the same way as when uploading (Escape cancels, 10-minute limit). The only thing that stays a local InputBox is the target folder (defaults to suggesting the last one used — the same preference as the target folder in EasyPDMUpload.bas, so sent and downloaded files can land in one place).
  3. For an Assembly: it also fetches all of its components recursively (direct children, then their children, and so on — the whole BOM), into the SAME folder as the main file. Without this, an assembly built on external references to saved files (typical in SolidWorks) would have nothing to open against.
  4. For each file: if there's already a file in the folder with EXACTLY the same name (i.e., the same revision) and the same size as on the server — it's skipped (not downloaded again). If there's a file for this item at a different (older) revision, and there's a newer one on the server — it asks whether to download the newer one.
  5. At the end, it opens the main (chosen) file in SolidWorks (swApp.OpenDoc6) — component files stay only on disk, SolidWorks resolves the assembly references to them on its own.

Where it gets the files to download from: EasyPDM stores the current CAD file as an attachment (there's no separate "item file" mechanism), and earlier revisions stay as separate attachments alongside it — EasyPDMDownload.bas recognizes the naming convention set by EasyPDMUpload.bas, in order to land on the attachment corresponding to the CURRENT revision; if an item has never gone through any CAD macro (attached manually in the web application), it simply takes the most recently uploaded attachment.

How to check whether it worked

Three independent ways, from the fastest to the most detailed:

  1. The web application while it runs — the transfer list on the right ticks each file off, and at the end the bell (notifications) holds a report: how many files went up or came down, which failed, which were skipped. A window with "Error: ..." in SolidWorks means something went wrong.

  2. The item itself — the most reliable proof for an upload: go into the project (or "Whole database"), find the item and check whether it has an attached file (properties panel → Attachments) and correct properties.

  3. The macro log — every run appends (does not overwrite) a detailed, timestamped record to a plain text file (a separate file for each macro, so they don't get mixed up):

    %TEMP%\EasyPDM_macro.log            <- EasyPDMUpload.bas
    %TEMP%\EasyPDM_download_macro.log   <- EasyPDMDownload.bas
    

    (paste %TEMP% into Windows Explorer's address bar to get there). Contains, among other things, every API call with the response code (GET /items -> 200), the login result, whether the file storage was visible from this machine, whether the file was copied/registered/downloaded successfully, and the full error text if something failed. This is the first place to check when something isn't working — the path to it is also appended in the error/success window at the end.

Installation

SolidWorks has no plain-text macro format (like FreeCAD's Python) — macros are VBA projects. .bas is the standard export/import format for a VBA module (not the whole macro project), so for EACH of the two files separately:

  1. SolidWorks → Tools → Macro → New... — create a new (empty) macro project and save it (e.g. EasyPDMUpload.swp / EasyPDMDownload.swp).
  2. In the opened VBA editor: File → Import File... → point to EasyPDMUpload.bas or EasyPDMDownload.bas. If the project still has an empty, auto-generated module (typically Module1/Upload1) — remove it (right-click in the project tree → Remove... → No, when asked about exporting), so as not to leave two modules at once.
  3. Run it via Tools → Macro → Run (pointing to the saved .swp file) or directly from the VBA editor (F5, with the cursor inside Sub main() — if the project has other procedures, F5 runs whichever one the cursor is currently in, not always main automatically).
  4. A separate Sub Logout (in each of the modules) logs out of EasyPDM — it can be bound to your own button/shortcut in SolidWorks.

The API address (default http://localhost:5000/api) is saved automatically after being entered once at login — shared by both macros.

The EasyPDM add-in

Addin/ is a SOLIDWORKS add-in with an EasyPDM tab (Upload, Download, Lock, Log in/out, Panel) that runs these macros, and a document panel with the outdated-component check of its own; it comes with every release. Without it, the four macro commands can be put on a toolbar by hand:

An EasyPDM toolbar

SolidWorks can put macro procedures on toolbar buttons, which gives the same four commands as the FreeCAD add-on without a compiled add-in. Tools → Customize → Commands → Macro, drag the "New Macro Button" onto a toolbar four times and point each at:

Button Macro Procedure (module EasyPDMUpload / EasyPDMDownload)
Upload EasyPDMUpload.swp main
Download EasyPDMDownload.swp main
Log in EasyPDMUpload.swp LoginInBrowser
Log out EasyPDMUpload.swp Logout

Log in (LoginInBrowser, EasyPDM servers from 0.9) asks for the server address, opens EasyPDM in the browser with a code, and after you click Allow there and OK in SolidWorks stores the macro's own token — the password never passes through SolidWorks. Upload and Download start the same sign-in by themselves when there is no valid login; only for servers older than 0.9 do they ask for a login and password instead.

History of fixed issues

Found and fixed on 2026-08-20, during the first real test of EasyPDMUpload.bas on live SolidWorks 2026 — left here as a documented example of the kind of VBA-specific gotcha this codebase has hit before (both macros now share this fixed infrastructure):

  1. No session token in the login body — MSXML2.XMLHTTP.6.0 did not give reliable access to the Set-Cookie header. Fixed server-side (POST /auth/login adds sessionToken straight into the JSON body) — applies to both macros.
  2. Undeclared SolidWorks constants (swCustomInfoText, swCustomPropertyReplaceValue, swDocPART, swDocASSEMBLY) — the whole module deliberately uses late binding (type Object instead of SldWorks.*), so the bare names of SolidWorks enums had nowhere to get their values from. Fixed with explicit Long constants with documented values from the SolidWorks API, grouped right at the start of the module.
  3. swApp undeclared — CONTRARY to an earlier assumption, swApp is NOT automatically visible in every VBA module of a project, only in the one SolidWorks itself generated on "New...". An imported module needs its own declaration and assignment (Set swApp = Application.SldWorks) at the start of main().
  4. Mojibake of Polish characters — VBA did not import the .bas file as UTF-8; Polish characters (in comments AND in windows visible to the user) came out as garbage. Fixed by translating the whole file into plain ASCII (English).
  5. MSXML2.XMLHTTP.send() rejected a bare Byte() array ("The parameter is incorrect") when uploading through the HTTP fallback. An initial attempt wrapped the bytes in a binary ADODB.Stream sent through the same MSXML2.XMLHTTP object — this itself still failed on a real upload with a generic "NO CONNECTION" error. The actual fix: ApiUploadFile switched specifically to WinHttp.WinHttpRequest.5.1, which accepts a Byte() array directly via .Send(); every other call (ApiGet, login, etc.) kept using MSXML2.XMLHTTP.6.0 until 2026-11 (see below).

Later rounds of live testing (through 2026-08-27) found and fixed several more issues, summarized here rather than item-by-item — see git history for the full detail: Lightweight assembly components not being detected (ResolveAllLightWeightComponents must be called directly on the model, not through .Extension, which silently no-ops); MSXML2.XMLHTTP.6.0 GET requests being served from Windows' local HTTP cache indefinitely, fixed by adding Cache-Control/Pragma headers plus a _ts= cache-busting query parameter to every ApiGet call in both files (each has its own independent copy of ApiGet, and EasyPDMDownload.bas additionally needed the same fix in ApiGetBinary, since a stale cached response there would silently corrupt the downloaded file's actual bytes, not just a status field); a new assembly component showing up as an unwanted duplicate at the project root, fixed by explicitly hiding newly-created leaf items from the tree root once attached to their real parent; and repeated "cad"-role attachments accumulating on every save at the same revision, fixed by checking for and deleting an existing same-filename attachment before the plain-HTTP upload fallback.

Found on 2026-11-17 on SOLIDWORKS 2024 SP5: after signing in through the browser, every request was refused (/auth/device/token -> 200, then /auth/me -> 401), while a password login kept working. MSXML2.XMLHTTP.6.0 runs on WinINet, whose cookie jar is shared with Internet Explorer: the password login (/auth/macro-login) answers with a pdm_session cookie, WinINet kept it and sent it beside the token the macro sets by hand, and after a logout that cookie held a revoked token, which the server read. Both macros now use MSXML2.ServerXMLHTTP.6.0 (the same interface on WinHTTP, which has no shared cookie jar and no cache), with timeouts raised to 10 minutes for large files.

Known risks / places to check first

The main flows are now live-verified (see "Status" above). What remains genuinely untested are a few narrow, low-traffic details, marked UNVERIFIED inline in the source:

  1. IModelDocExtension.SaveAs exact parameter signature for .step/.pdf export (UploadStepAttachment/UploadPdfAttachment) — written from the SolidWorks API documentation; if SolidWorks reports an argument error, check the exact signature of the installed version in the VBA editor (F1 on SaveAs).
  2. The "save in the same format" path for a document that was already saved once this session (skips the full Save As dialog) — the common "just re-save and re-run the macro" case is well exercised, this specific branch less so.
  3. SW_SAVE_AS_SILENT's exact constant value, used to suppress SolidWorks' own confirmation dialogs during the STEP/PDF export SaveAs calls.

None of these have caused a reported failure so far — they're listed here as the first place to look if something SolidWorks-version-specific ever goes wrong with export or save behavior.

Limitations (deliberately out of scope for this version)

  • EasyPDMDownload.bas: does not try to download a SPECIFIC older revision — always targets the current one. All files (main + components) land flat in one folder, without recreating the BOM structure as subfolders.
  • The login password asked for by servers older than 0.9 is not masked (plain InputBox, with no dedicated UserForm).
  • The download's target folder is a plain InputBox with a path as text, not a system file browser.
  • Copying/registering/downloading a file through storage/ assumes this folder is visible in this machine's filesystem.

Drawing sheet with the title block

Two parts: a one-time setup macro that draws the EasyPDM sheet format, and the Upload macro, which fills it in every time a drawing is sent.

EasyPDMSheetFormat.bas — creating the sheet format (once)

Without the macro: the finished files are in templates/ — EasyPDM_A3/A2/A1_Landscape.slddrt (sheet format) and .drwdot (drawing template); the sheet in this folder is the current one. Put them in any folder, add it under Tools → Options → File Locations (Sheet Formats and Document Templates) and start drawings from the template; step 3 below is the same. The macro is for building them yourself, e.g. after changing build_templates.py — and then the files in templates/ have to be rebuilt and committed too, as only SolidWorks can write them.

It draws the EasyPDM sheet format — the same frame, ISO 5457 grid references and title block as the FreeCAD templates — on the current sheet of a drawing and saves it as a sheet format (.slddrt) and a drawing template (.drwdot) in Documents\EasyPDM\SolidWorks.

  1. File → New → Drawing at A3, A2 or A1 (landscape), on a sheet with an empty sheet format (delete the contents of the standard "a3 - iso" format first, or start from an empty one).
  2. Run EasyPDMSheetFormat.bas (main) and confirm.
  3. Tools → Options → File Locations: add that folder to Sheet Formats and Document Templates, and start new drawings from EasyPDM_A3_Landscape.drwdot (or A2 / A1).

Title block fields are notes linked to the drawing's custom properties ($PRP:"pdm_drawn_by", $PRP:"pdm_label_drawn_by", …); scale and sheet number use SolidWorks's own sheet properties. The macro is generated by tools/build_templates.py in pawelcel/EasyPDM-FreeCAD (--solidworks PATH-TO-THIS-REPOSITORY) — edit the script, not the .bas. Each run writes a log to %TEMP%\EasyPDM_sheetformat.log, whose first line names the macro revision.

Filling it in — the Upload macro

When you upload a drawing that uses the EasyPDM sheet, Upload — before it saves the drawing and exports its PDF — reads the item's title block data from EasyPDM and:

  • writes the pdm_* properties: approved by with its date (current revision only), name with its translations (multilingual projects), drawing number, revision, material, mass, company, and every label in the project's main language;
  • builds a processes table above the title block (anchored to its top edge, growing upward, header in the last row) and a revision table in the top-right corner (B, C, …; revision A is not listed) — SolidWorks general tables;
  • puts the company logo in the square at the right end of the NAME row.

Running Upload again replaces only its own tables and logo — features named "EasyPDM processes", "EasyPDM revisions" and "EasyPDM logo" in the FeatureManager tree; tables and pictures you placed yourself stay. (Don't rename those three.) A drawing with any other sheet format is left alone. A part or assembly upload never exports a PDF — the item's PDF is its drawing.

DRAWN BY is left empty: it is whoever sends the revision for review, not whoever exports the drawing. The PDF of a drawing on an EasyPDM A3, A2 or A1 sheet is marked as such when it is sent; when the item is sent for review the server writes the sender's name and the date into its DRAWN BY field, and when it is released the approver's into APPROVED BY — so the PDF in EasyPDM carries both even though a released item cannot be uploaded again. The .slddrw itself keeps those fields empty.

About

SolidWorks add-in and macros for EasyPDM, a small self-hosted PDM

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages