solidworks_mcp.agents.soc_pickup¶
solidworks_mcp.agents.soc_pickup ¶
SolidWorks-as-Code pickup: reverse-engineer manual changes into the script.
When you make changes directly in SolidWorks after the last checkpoint (adding a fillet, a hole, a sketch, etc.), this module detects them by diffing the current feature tree against the last saved ModelStateSnapshot and emits new script lines for the delta.
The pickup result can be appended to the existing generated script, and a new checkpoint is created so subsequent pickups only diff against the new state.
Feature type coverage
─────────────────────
+--------------------------+--------------------------------------------------+
| Feature type keyword | Emitted code |
+--------------------------+--------------------------------------------------+
| Boss-Extrude / Extrude | create_extrusion(ExtrusionParameters(depth=?)) |
| Cut-Extrude / CutExtrude | create_cut_extrude(ExtrusionParameters(depth=?)) |
| Fillet / Round | add_fillet(radius=?, edge_names=[...]) |
| Chamfer | # TODO: add_chamfer(...) |
| Sketch | create_sketch(...); exit_sketch() |
| Reference plane | # TODO: add reference plane |
| Mirror / Pattern | # TODO: mirror / pattern feature |
| Everything else | # TODO: reconstruct
Depth/radius values cannot be read without a live SolidWorks connection. Placeholders are left for the user to fill in.
Usage::
from solidworks_mcp.agents.soc_pickup import pickup_changes
delta_lines = await pickup_changes(
adapter,
session_id="my-session",
checkpoint_label="post-pickup-1", # label for the new checkpoint
output_path="my_part.py", # append to existing script
)
print("\n".join(delta_lines))
Attributes¶
_CUT_KEYWORDS
module-attribute
¶
_EXTRUDE_KEYWORDS
module-attribute
¶
_PATTERN_KEYWORDS
module-attribute
¶
Functions:¶
_classify ¶
Source code in src/solidworks_mcp/agents/soc_pickup.py
_cli ¶
Source code in src/solidworks_mcp/agents/soc_pickup.py
_feature_key ¶
Stable identity for a feature row: (owning component, name).
An assembly's flattened feature list commonly has the same name
(e.g. "Boss-Extrude1") in several different components, so bare name
alone isn't unique across an assembly. Pairing it with component
(None for a document's own features) disambiguates that while
leaving Part-only trees - where every row's component is None
- behaving exactly as bare-name comparison did before.
Source code in src/solidworks_mcp/agents/soc_pickup.py
_feature_map ¶
_feature_names ¶
_feature_type ¶
diff_feature_trees ¶
diff_feature_trees(old_tree: list[dict[str, Any]], new_tree: list[dict[str, Any]]) -> list[dict[str, Any]]
Return features present in new_tree but not in old_tree (by component+name).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_tree
|
list[dict[str, Any]]
|
Feature list from the last ModelStateSnapshot. |
required |
new_tree
|
list[dict[str, Any]]
|
Current feature list from list_features(). |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of new feature dicts, in the order they appear in new_tree. |
Source code in src/solidworks_mcp/agents/soc_pickup.py
emit_feature_lines ¶
Emit Python code lines for a single newly-detected feature.
Values that require querying the COM API are left as '?' placeholders.
Source code in src/solidworks_mcp/agents/soc_pickup.py
generate_pickup_lines ¶
Generate script lines for a list of new features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_features
|
list[dict[str, Any]]
|
Features returned by diff_feature_trees(). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of Python source lines (without trailing newlines). |
Source code in src/solidworks_mcp/agents/soc_pickup.py
pickup_changes
async
¶
pickup_changes(adapter: Any, session_id: str, *, checkpoint_label: str = 'pickup', output_path: str | Path | None = None, db_path: Path | None = None) -> list[str]
Diff current feature tree against last snapshot and emit delta lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
Connected SolidWorks adapter. |
required |
session_id
|
str
|
The SoC session ID. |
required |
checkpoint_label
|
str
|
Label for the new checkpoint created after pickup. |
'pickup'
|
output_path
|
str | Path | None
|
If set, append the pickup lines to this .py script file. |
None
|
db_path
|
Path | None
|
Override default SQLite DB path. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of generated Python source lines for the new features. |
Source code in src/solidworks_mcp/agents/soc_pickup.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |