agentleFS
BaratiLabBaratiLab/mechanical-engineering-skills/skills/query2cad-freecad/SKILL.md

query2cad-freecad

Skill16 starsChanged 16 days agoMITView on GitHub

Generates FreeCAD CAD models from natural-language queries with the Query2CAD self-refinement loop — plan steps, write a FreeCAD Python macro, repair execution errors (≤3), capture an isometric view, score image-text agreement (VQAScore ≥ 0.9 to stop), and refine from a caption of what was actually built (≤3), with optional human feedback. Use when the user wants a FreeCAD macro or FreeCAD model from a description, works in FreeCAD, or asks for conversational/iterative CAD from plain language.

  • Installs packages

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When to prefer the alternatives: CADSmith (cadsmith-text-to-cad) gives kernel-checked dimensional accuracy in CadQuery.

    line 10
  2. Very specific:

    Steps first: Write the construction steps in plain language: components, dimensions (assume sensible mm values and list them), placement …

    line 15
  3. Distinctive:

    Stop or refine (model refinement, at most 3): If score ≥ 0.9, accept. Otherwise:

    line 27

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 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

Query2CAD: natural language → FreeCAD macro with self-refinement

Paper: A. Badagabettu, S. S. Yarlagadda, A. Barati Farimani, Query2CAD: Generating CAD models using natural language queries, arXiv:2406.00144 (code: github.com/akshay140601/Query2CAD). With GPT-4 Turbo, success went from 53.6% on the first try to 73.2% after one refinement and 76.7% after three (easy 95%, medium 70%, hard 42%). Most of the gain comes from the first refinement, and most failures (69%) were macros that never executed.

When to prefer the alternatives: CADSmith (cadsmith-text-to-cad) gives kernel-checked dimensional accuracy in CadQuery. Use Query2CAD when the user lives in FreeCAD, wants a .FCMacro, or the query is conceptual ("a basketball hoop", "a bookshelf") rather than dimension-exact.

Requires FreeCAD with freecadcmd on PATH, or FREECAD_CMD set. Tested headless with FreeCAD 26.3 from conda-forge: micromamba create -p ./fc -c conda-forge freecad python=3.11, then export FREECAD_CMD=./fc/bin/freecadcmd. The AppImage and Homebrew builds also work. Rendering uses pyvista. VQAScore optionally uses pip install t2v-metrics. Q = scripts/q2c.py.

Workflow

  1. Steps first. Write the construction steps in plain language: components, dimensions (assume sensible mm values and list them), placement relationships. Then write macro.py using references/freecad_macros.md (headless: no FreeCADGui).
  2. Execute (error refinement, at most 3).
    python $Q run runs/q/macro.py --out runs/q/v0
    On failure, give yourself the code and traceback, fix only the error, then run python $Q log --run runs/q --kind error --note "<error>". If the budget runs out, report a non-executable macro.
  3. Capture and score.
    python $Q render runs/q/v0.stl --out runs/q/v0_iso.png
    python $Q score  --image runs/q/v0_iso.png --query "<user query>"
    VQAScore = P("Yes" | image, "Does this figure show {query}? Please answer yes or no."). If t2v_metrics isn't installed, answer that question yourself from the image as a calibrated probability and log it as --judged-by agent. Be strict: a pentagon isn't a star.
  4. Stop or refine (model refinement, at most 3). If score ≥ 0.9, accept. Otherwise:
    • Caption the isometric image: describe only what is actually there (shapes, counts, arrangement), not what was intended. The paper used BLIP-2 for this. Its captions were often accurate but too thin to guide the fix, so add specifics. Ask the user for a correction when they're present; the paper's human-in-the-loop captions worked best.
    • Diff the caption against the query, revise the macro, run python $Q log --run runs/q --kind model --note "<caption + diff>" --score <s>, and go back to step 2.
  5. Deliver the .FCMacro (rename macro.py), STEP/STL, the isometric image, the score history from the ledger, and the assumed dimensions.

Example of the refinement signal (from the paper)

Query: "a plate in the shape of a star". v0 drew an open pentagon outline. Caption feedback, "an open pentagon outline", led to v1, a closed pentagon plate. Caption "a pentagonal plate" plus the diff "needs 5 pointed tips" led to v2, a star-shaped plate. The fix comes from the gap between what was built and what was asked for.

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.