com-api-pitfalls

A troubleshooting reference for SolidWorks COM calls made through pywin32. COM is the Windows interface SolidWorks exposes for programmatic control, and pywin32 lets Python call it.

In plain words
What is it for?
Use it before changing COM-related code, especially selection calls such as SelectByID2, to check required argument types and avoid documented integration failures.
Why use it?
Some values that look valid in Python are sent in the wrong COM type and cause runtime errors. The guide records these pitfalls and their known fixes.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/andrewbartels1/solidworksmcp-python/com-api-pitfalls
Clone the repo
git clone --depth 1 https://github.com/andrewbartels1/SolidworksMCP-python
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 6,513 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.06513
Opus 5 $0.00000 $0.03256
Sonnet 5 $0.00000 $0.01303
Haiku 4.5 $0.00000 $0.00651

Measured yesterday against content hash e39c150c9582, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

com-api-pitfalls scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/agents/com-api-pitfalls.md · 584 lines

How it starts

The opening of the file, as written. The whole thing — 584 lines — stays where its author put it; the contents beside it link to each section on GitHub.

COM API Pitfalls for LLM Agents

This page documents hard-won lessons from debugging the SolidWorks COM bridge. If you are an AI coding assistant (Claude, GPT-4, Gemini, Copilot, etc.) working on this codebase, read this page before touching any COM-related code. Every entry below caused a real runtime failure that required hours to diagnose.

!!! tip "For LLM agents" The patterns here are not obvious from the SolidWorks API docs alone. They are the delta between "what the documentation says" and "what actually works" under pywin32 late-binding on SW 2025/2026.


1. SelectByID2Callout must be VT_DISPATCH null, not None

Symptom: (-2147352571, 'Type mismatch.', None, 8) when calling SelectByID2.

Root cause: The Callout parameter (8th argument, type VT_DISPATCH) expects a COM null pointer, not a Python None. Python None marshals as VT_NULL which SolidWorks rejects with DISP_E_TYPEMISMATCH.

Fix:

import pythoncom
import win32com.client as _win32com

null_callout = _win32com.VARIANT(pythoncom.VT_DISPATCH, None)
model.Extension.SelectByID2(
    "", "EDGE", x, y, z,
    append, mark,
    null_callout,   # <- NOT plain None
    0,
)

Applies to: Every call to SelectByID2 or SelectByID that doesn't need a real callout object. The same issue occurs for FACE, EDGE, VERTEX, and other entity types.


2. InsertFeatureChamfer lives on IFeatureManager, not IModelDocExtension

Symptom: <unknown>.InsertFeatureChamfer error when calling through model.Extension.

Root cause: InsertFeatureChamfer (DISPID 83) is a method of IFeatureManager, not IModelDocExtension. Routing it through model.Extension causes DISP_E_MEMBERNOTFOUND.

Fix:

import math

fm = model.FeatureManager          # IFeatureManager (property access, no parens)
feature = fm.InsertFeatureChamfer(
    1,                             # Options
    1,                             # ChamferType = swChamferEqualDistance
    distance_m,                    # Width in metres
    math.pi / 4,                   # Angle (45 degrees)
    0.0,                           # OtherDist (unused for equal-distance)
    0.0, 0.0, 0.0,                 # VertexChamDist1, 2, 3 (unused)
)

Read the full file on GitHub · 584 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 584 lines · 0 tokens per session scan A e39c150c9582

Subscribe to this mod's changes

com-api-pitfalls is an agent published in the GitHub repository andrewbartels1/SolidworksMCP-python (65 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 6,513 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.