agentleFS
RileyCorneliusRileyCornelius/Code-Skills/solidworks/SKILL.md

solidworks

Skill0 starsChanged 7 months agoMITView on GitHub

Operate SolidWorks on Windows through Python COM - create or edit parts, build assemblies with real mates, make drawings, export STEP/STL/IGES/PDF/DXF, measure mass properties and interference, and deliver CAD with verified evidence. Use when the user asks an agent to model, modify, inspect, export, review or qualify anything in SolidWorks (.sldprt, .sldasm, .slddrw), or to automate SolidWorks with Python or the SolidWorks API.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. About 0 are common, 9 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when an agent must operate SolidWorks as a tool, not only write a macro.

    line 10
  2. Distinctive:

    Before claiming that SolidWorks was controlled or that any artifact was created, prove that the current runtime can:

    line 24
  3. Distinctive:

    import the required COM dependencies.

    line 29
  4. Very specific:

    Run python <skill-dir>/scripts/sw_preflight.py --no-install and read its output.

    line 33
  5. Distinctive:

    Never claim that a file was generated, verified, attached, uploaded, or made downloadable unless a tool created it and you inspected its …

    line 40
  6. Distinctive:

    Never start a second SolidWorks.

    line 52
  7. Very specific:

    Create, open and import through sw_documents.new_owned/open_owned/import_owned, and close only with DocumentOwnership.close/close_all.

    line 58
  8. Distinctive:

    Before changing CAD, record:

    line 65
  9. Distinctive:

    Never overwrite the user's only source model.

    line 73
  10. Very specific:

    Use the Python helpers in scripts/ rather than generated VBA.

    line 80
  11. Very specific:

    After each topology change: rebuild, then measure with sw_inspect (feature health, body count, volume, mass properties, envelope).

    line 83
  12. Distinctive:

    Look at the preview images.

    line 86
  13. Very specific:

    Use the feature object or ActiveSketch.Name that the API returns.

    line 157
  14. Very specific:

    Add named driving dimensions for interfaces, then require a fully defined sketch (sw_inspect.fully_define_active_sketch).

    line 161
  15. Very specific:

    Verify transforms, constrained states, intended free motion (sw_runtime.transform_and_solve), and interference.

    line 172
  16. Distinctive:

    Read only what the task needs:

    line 204

≈ “Common” is an estimate: at least 1 in 5 of the 383,637 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SolidWorks

Use this skill when an agent must operate SolidWorks as a tool, not only write a macro. The result is a reproducible CAD artifact plus evidence that it was rebuilt, measured, saved, exported and reviewed.

<skill-dir> below is the directory that contains this file (in Claude Code: ${CLAUDE_SKILL_DIR}). Helpers live in <skill-dir>/scripts:

import sys
sys.path.insert(0, r"<skill-dir>/scripts")

Capability gate

Before claiming that SolidWorks was controlled or that any artifact was created, prove that the current runtime can:

  • execute a real local shell and Python process;
  • access the requested Windows output directory;
  • import the required COM dependencies; and
  • connect to SldWorks.Application in the same interactive Windows session as SolidWorks.

Run python <skill-dir>/scripts/sw_preflight.py --no-install and read its output. If dependencies are missing, ask the user before installing pywin32 and comtypes. If the runtime cannot run commands, reach the user's files, or reach the SolidWorks COM session, stop and say that you can only provide instructions or code. Uploading this repository as chat knowledge does not grant local shell, filesystem, COM, or desktop access.

Never claim that a file was generated, verified, attached, uploaded, or made downloadable unless a tool created it and you inspected its absolute path, size, and modification time. Do not present plain text as a download link, invent an attachment, or send the user to look for an artifact the runtime did not produce. Keep the requested file name consistent from creation through delivery.

Session safety

The user may have their own work open. Read references/session-safety.md before the first COM call in a session.

  1. python <skill-dir>/scripts/sw_resource_guard.py --target solidworks --allow-reuse. Never start a second SolidWorks. Never kill a process you did not start.
  2. Attach to the running SolidWorks with sw_runtime.attach(major). Pin the major version (2024 = 32, 2025 = 33) when more than one release is installed. If none is running, ask the user before launching one.
  3. List open documents with sw_documents.open_document_report(app). Do not save, close, rebuild or edit documents you did not create or open in this process.
  4. Create, open and import through sw_documents.new_owned/open_owned/import_owned, and close only with DocumentOwnership.close/close_all.
  5. Change user preferences only inside a restoring context such as sw_runtime.no_dimension_input_dialog(app).

Operating contract

Before changing CAD, record:

  • the source model and whether it may be modified (default: work on a copy);
  • units, interfaces, invariants, tolerances and material assumptions;
  • the outputs required (.SLDPRT, .SLDASM, .SLDDRW, STEP, STL, PDF, previews);
  • acceptance checks (rebuild, body count, dimensions, volumes, mates, interference);
  • unknown values as null. Never guess a dimension; ask or record an explicit assumption.

Never overwrite the user's only source model. Keep source, generated CAD, exports, previews and evidence as separate artifacts.

Agent loop

  1. Preflight, resource guard, attach (above).
  2. Turn the request into inputs, constraints, outputs and checks.
  3. Use the Python helpers in scripts/ rather than generated VBA.
  4. Build one small stage at a time. Check every COM return value: None, False, a nonzero error code or an unexpected body count is a failure, even if a file was written.
  5. After each topology change: rebuild, then measure with sw_inspect (feature health, body count, volume, mass properties, envelope).
  6. Save, export, then run sw_review.run_review() for previews and delivery hygiene.
  7. Look at the preview images. Rule-based review cannot prove geometric intent.
  8. On failure, classify it first: environment, selection, geometry, rebuild, export, path/encoding, dialog, timeout, or resource conflict. Change one variable and retry from the earliest uncertain stage, with a bounded number of attempts.
  9. Finish only when the required artifacts and evidence exist. Report each artifact's verified absolute paths, sizes, and modification times.

scripts/sw_evidence.py records atomic JSON evidence with SHA-256 per artifact and refuses release while checks are missing or a visual review is pending. scripts/sw_agent_loop.py enforces the workflow states (references/agent-loop.md).

Modules

NeedModule
Environment and dependency checkssw_preflight.py
Single heavyweight CAD/CAE instancesw_resource_guard.py
Attach, version pinning, preferences, transformssw_runtime.py
Document ownership and safe open/import/closesw_documents.py
Legacy connect/open/save helpers and session facadesw_connect.py, sw_session.py
Sketches and part featuressw_part.py
Components, real mates, interferencesw_assembly.py
Mass properties, feature health, sketch state, references, BOM/PDF readbacksw_inspect.py
Drawingssw_drawing.py
STEP/STL/IGES/PDF/DXF exportsw_export.py
Portable packages and reference repointingsw_package.py
Multi-view previews and review reportsw_review.py
Structured evidence and workflow statessw_evidence.py, sw_agent_loop.py
Guarded generated VBA (last resort)sw_macro_guard.py
Appearance colorssw_appearance.py

Minimal part workflow

import sys
sys.path.insert(0, r"<skill-dir>/scripts")

from sw_connect import mm, save_document
from sw_documents import DocumentOwnership, new_owned
from sw_export import export_to_step
from sw_inspect import snapshot
from sw_part import extrude_boss, sketch, sketch_circle
from sw_review import run_review
from sw_runtime import attach, default_template, no_dimension_input_dialog

app, revision = attach(33)
ownership = DocumentOwnership(app)
with no_dimension_input_dialog(app):
    model = new_owned(app, ownership, default_template(app, "part"))
    with sketch(model, "Front Plane") as sketch_name:
        sketch_circle(model, 0, 0, mm(25))
    extrude_boss(model, sketch_name, mm(50))          # raises if no feature is returned
    state = snapshot(model)                           # raises unless the rebuild succeeds
    assert state["bodies"] == 1
    expected = 3.141592653589793 * mm(25) ** 2 * mm(50)
    assert abs(state["mass"]["volume_m3"] - expected) < 1e-9
    assert save_document(model, r"C:\cad-output\cylinder.sldprt")
    assert export_to_step(model, r"C:\cad-output\cylinder.step")
    report, report_path = run_review(model, r"C:\cad-output\review", basename="cylinder",
                                     expected_outputs=[r"C:\cad-output\cylinder.sldprt",
                                                       r"C:\cad-output\cylinder.step"])
    if report["evaluation"]["status"] == "fail":
        raise RuntimeError(f"CAD review failed: {report_path}")
ownership.close_all()

SolidWorks API lengths are meters and angles are radians. Convert at the boundary with mm() and deg().

Parts

  • Use the feature object or ActiveSketch.Name that the API returns. Do not guess localized names such as Sketch7.
  • Select the exact profile or feature before a dependent feature. Clear selection before and after fragile operations.
  • Add named driving dimensions for interfaces, then require a fully defined sketch (sw_inspect.fully_define_active_sketch). See references/part-modeling.md.
  • In inherited feature trees, keep dimension identities (D2@Sketch2) until their meaning is confirmed; treat pattern counts as topology, not a continuous parameter.

Assemblies

  • AddComponent4(x, y, z) only sets an initial position. It does not make an assembly.
  • Fix one datum component. Mate the rest with real mates found by geometry (radius, axis, plane normal and position), not by face names.
  • Accept AddMate5 only when the mate is non-null and its error status is 1.
  • Verify transforms, constrained states, intended free motion (sw_runtime.transform_and_solve), and interference. A skipped interference scan is reported as skipped, never as zero. See references/assembly.md.

Drawings and export

  • PDF export needs the attached application: export_to_pdf(drawing, path, ["Sheet1"], sw=app). IModelDoc2 has no GetSldWorksObject. Prove the sheet set with sw_inspect.pdf_page_texts().
  • BOM tables go on the owning view: insert_bom_table(..., view=view); read them back with sw_inspect.table_cells().
  • See references/drawing.md and references/export.md.

Completion evidence

A finished run includes:

  • source provenance and the confirmed request contract;
  • native CAD and the requested neutral exports, with SHA-256, size and mtime;
  • rebuild and feature-health results, body/component counts, mass properties;
  • mate states and interference results for assemblies;
  • isometric plus orthographic previews, and the visual review result you recorded;
  • residual uncertainty stated plainly.

Qualify an installation

Unit tests use fake COM objects. To prove a SolidWorks installation behaves as these helpers expect, run the live suite in qualification/ (read its README first): it refuses to start with documents open and writes only to its output directory.

References

Read only what the task needs:

  • references/session-safety.md - attach, ownership, preferences, transforms, packages
  • references/measurement.md - mass, feature health, sketch state, interference, readback
  • references/agent-loop.md - states, request contract, recovery policy
  • references/part-modeling.md, references/assembly.md, references/drawing.md, references/export.md, references/appearance.md, references/advanced.md
  • references/review.md - run_review() output and visual checklist
  • references/troubleshooting.md, references/com-survival-guide.md - COM failures
  • references/api-lookup.md - how to verify an unwrapped API before using it
  • references/agent-runtime.md - dependency-install consent, import template, macro guard

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.