MechanicsSketches Skill
You can generate engineering mechanics sketches programmatically using the MechanicsSketches Python library.
Setup
Install the library via pip:
pip install git+https://github.com/MatthiasHBusch/MechanicsSketches.git
Or install dependencies manually and add to PYTHONPATH:
pip install matplotlib PyQt5
export PYTHONPATH="/path/to/parent/of/MechanicsSketches:$PYTHONPATH"
Quick Start — Writing a Script
Create a Python script that builds a sketch and renders it:
from MechanicsSketches import *
import os
sketch = create_sketch("My Sketch")
S = 30.0 # Scale factor (recommended: 20-40)
# Add components
add_beam(sketch, ax=0, ay=0, bx=10*S, by=0, scale_factor=S)
add_pinned_support(sketch, cx=0, cy=0, angle_deg=0, scale_factor=S)
add_roller_support(sketch, cx=10*S, cy=0, angle_deg=0, scale_factor=S)
add_force(sketch, cx=5*S, cy=0, angle_deg=0, scale_factor=S, annotation=r"$F$")
# Render
script_dir = os.path.dirname(os.path.abspath(__file__))
render(sketch, filename=os.path.join(script_dir, "output.pdf"), dpi=300)
Then run: python my_sketch.py
Quick Start — Using the Helper Script
Alternatively, use the bundled helper to render from JSON:
python scripts/generate_sketch.py input.json output.pdf
Key Concepts
Scale Factor (S)
All positions and sizes should be multiples of S (typically 30.0). This keeps proportions consistent across components.
Angle Convention
angle_deg=0 → default orientation (upward for supports/forces, horizontal for dimensions)
- Angles rotate counterclockwise in degrees
Available Components
| Function |
Description |
Key Parameters |
add_beam(sketch, ax, ay, bx, by, scale_factor) |
Rectangular beam A→B |
Endpoints, scale |
add_truss(sketch, ax, ay, bx, by, scale_factor) |
Line member A→B |
Endpoints, scale |
add_pinned_support(sketch, cx, cy, angle_deg, scale_factor) |
Fixed-position support (triangle) |
Center, angle, scale |
add_roller_support(sketch, cx, cy, angle_deg, scale_factor) |
Sliding support |
Center, angle, scale |
add_fixed_support(sketch, cx, cy, angle_deg, scale_factor) |
Clamped wall support |
Center, angle, scale |
add_hinge(sketch, cx, cy, scale_factor) |
Joint circle |
Center, scale |
add_force(sketch, cx, cy, angle_deg, scale_factor, annotation, ...) |
Force arrow |
Center, angle, scale, label |
add_moment(sketch, cx, cy, angle_deg, scale_factor, annotation, ...) |
Curved moment arrow |
Center, angle, scale, label |
add_dimension_arrow(sketch, cx, cy, length, angle_deg, scale_factor, annotation, ...) |
Double-headed dimension |
Center, length, angle, scale, label |
add_dimension_thickness(sketch, cx, cy, thickness, angle_deg, scale_factor, annotation, ...) |
Inward dimension arrows |
Center, thickness, angle, scale, label |
add_coordinate_system(sketch, cx, cy, angle_deg, scale_factor, ax1, ax2, ax3, ...) |
x-y-z axes |
Center, angle, scale, axis labels |
add_text(sketch, x, y, text, fontsize, name, rotation) |
Text annotation |
Position, text, font size |
Annotation Parameters
Force, moment, and dimension functions accept:
annotation — LaTeX string (e.g., r"$F$", r"$M_A$")
fontsize_scale — relative font size (default 1.0)
offsetx, offsety — label position offset
rotate_annotation — rotate label with component (default False)
Primitives
For custom shapes, use:
make_line(x0, y0, x1, y1, linewidth, layer, edgecolor)
make_circle(x, y, r, linewidth, layer, facecolor, edgecolor)
make_polygon(points, linewidth, layer, facecolor, edgecolor)
make_arc(x, y, width, height, theta1, theta2, angle, linewidth, layer)
make_text(x, y, text, fontsize, layer, color, ha, va, rotation)
make_rectangle(x0, y0, x1, y1, ...)
Add to sketch via add_to_sketch(sketch, primitive).
Transformations
translate(obj, dx, dy) — move by offset
rotate(obj, cx, cy, angle_deg) — rotate around point
scale(obj, cx, cy, factor) — scale from center
All return new objects (non-destructive). Can be chained.
Rendering
render(sketch, filename="output.pdf", dpi=300) # Qt renderer (default, recommended)
mpl_render(sketch, filename="output.pdf") # Matplotlib fallback (deprecated, text scaling issues)
Supported formats: .pdf, .png, .jpg, .svg
Tips for the Agent
- Always define
S = 30.0 as the scale factor
- Place beams first, then supports at endpoints, then loads
- Use LaTeX for annotations:
r"$F$", r"$M_0$", r"$\ell$"
- For detailed API signatures, see
references/api_reference.md
- The
render() function requires a filename — it does not display interactively
- Do not use
mpl_render() — it is deprecated due to text scaling issues. Always use render().
External Endpoints
This skill makes no network requests. All processing is done locally.
Security & Privacy
- No data leaves your machine. The skill only reads local JSON files and writes local image/PDF output.
- No API keys or credentials are required.
- No telemetry or analytics.
- The helper script (
scripts/generate_sketch.py) only reads the input file specified by the user and writes to the specified output path.
Trust Statement
This skill is developed and maintained by MatthiasHBusch. The source code is fully open under the MIT license. All functionality runs locally with no external dependencies beyond standard Python packages (matplotlib, PyQt5).
1---2name: mechanics-sketches3description: Generate technical engineering mechanics sketches (beams, supports, forces, moments, dimensions, coordinate systems) as PDF/PNG/SVG using the MechanicsSketches Python library. Use this skill when asked to create free-body diagrams, structural sketches, or mechanical engineering figures.4license: MIT5---6
7# MechanicsSketches Skill
8
9You can generate engineering mechanics sketches programmatically using the **MechanicsSketches** Python library.
10
11## Setup
12
13Install the library via pip:
14
15```bash
16pip install git+https://github.com/MatthiasHBusch/MechanicsSketches.git
17```
18
19Or install dependencies manually and add to `PYTHONPATH`:
20
21```bash
22pip install matplotlib PyQt5
23export PYTHONPATH="/path/to/parent/of/MechanicsSketches:$PYTHONPATH"
24```
25
26## Quick Start — Writing a Script
27
28Create a Python script that builds a sketch and renders it:
29
30```python
31from MechanicsSketches import *
32import os
33
34sketch = create_sketch("My Sketch")
35S = 30.0 # Scale factor (recommended: 20-40)
36
37# Add components
38add_beam(sketch, ax=0, ay=0, bx=10*S, by=0, scale_factor=S)
39add_pinned_support(sketch, cx=0, cy=0, angle_deg=0, scale_factor=S)
40add_roller_support(sketch, cx=10*S, cy=0, angle_deg=0, scale_factor=S)
41add_force(sketch, cx=5*S, cy=0, angle_deg=0, scale_factor=S, annotation=r"$F$")
42
43# Render
44script_dir = os.path.dirname(os.path.abspath(__file__))
45render(sketch, filename=os.path.join(script_dir, "output.pdf"), dpi=300)
46```
47
48Then run: `python my_sketch.py`
49
50## Quick Start — Using the Helper Script
51
52Alternatively, use the bundled helper to render from JSON:
53
54```bash
55python scripts/generate_sketch.py input.json output.pdf
56```
57
58## Key Concepts
59
60### Scale Factor (`S`)
61
62All positions and sizes should be multiples of `S` (typically 30.0). This keeps proportions consistent across components.
63
64### Angle Convention
65
66- `angle_deg=0` → default orientation (upward for supports/forces, horizontal for dimensions)
67- Angles rotate counterclockwise in degrees
68
69### Available Components
70
71| Function | Description | Key Parameters |
72|----------|-------------|----------------|
73| `add_beam(sketch, ax, ay, bx, by, scale_factor)` | Rectangular beam A→B | Endpoints, scale |
74| `add_truss(sketch, ax, ay, bx, by, scale_factor)` | Line member A→B | Endpoints, scale |
75| `add_pinned_support(sketch, cx, cy, angle_deg, scale_factor)` | Fixed-position support (triangle) | Center, angle, scale |
76| `add_roller_support(sketch, cx, cy, angle_deg, scale_factor)` | Sliding support | Center, angle, scale |
77| `add_fixed_support(sketch, cx, cy, angle_deg, scale_factor)` | Clamped wall support | Center, angle, scale |
78| `add_hinge(sketch, cx, cy, scale_factor)` | Joint circle | Center, scale |
79| `add_force(sketch, cx, cy, angle_deg, scale_factor, annotation, ...)` | Force arrow | Center, angle, scale, label |
80| `add_moment(sketch, cx, cy, angle_deg, scale_factor, annotation, ...)` | Curved moment arrow | Center, angle, scale, label |
81| `add_dimension_arrow(sketch, cx, cy, length, angle_deg, scale_factor, annotation, ...)` | Double-headed dimension | Center, length, angle, scale, label |
82| `add_dimension_thickness(sketch, cx, cy, thickness, angle_deg, scale_factor, annotation, ...)` | Inward dimension arrows | Center, thickness, angle, scale, label |
83| `add_coordinate_system(sketch, cx, cy, angle_deg, scale_factor, ax1, ax2, ax3, ...)` | x-y-z axes | Center, angle, scale, axis labels |
84| `add_text(sketch, x, y, text, fontsize, name, rotation)` | Text annotation | Position, text, font size |
85
86### Annotation Parameters
87
88Force, moment, and dimension functions accept:
89- `annotation` — LaTeX string (e.g., `r"$F$"`, `r"$M_A$"`)
90- `fontsize_scale` — relative font size (default 1.0)
91- `offsetx`, `offsety` — label position offset
92- `rotate_annotation` — rotate label with component (default False)
93
94### Primitives
95
96For custom shapes, use:
97- `make_line(x0, y0, x1, y1, linewidth, layer, edgecolor)`
98- `make_circle(x, y, r, linewidth, layer, facecolor, edgecolor)`
99- `make_polygon(points, linewidth, layer, facecolor, edgecolor)`
100- `make_arc(x, y, width, height, theta1, theta2, angle, linewidth, layer)`
101- `make_text(x, y, text, fontsize, layer, color, ha, va, rotation)`
102- `make_rectangle(x0, y0, x1, y1, ...)`
103
104Add to sketch via `add_to_sketch(sketch, primitive)`.
105
106### Transformations
107
108- `translate(obj, dx, dy)` — move by offset
109- `rotate(obj, cx, cy, angle_deg)` — rotate around point
110- `scale(obj, cx, cy, factor)` — scale from center
111
112All return new objects (non-destructive). Can be chained.
113
114### Rendering
115
116```python
117render(sketch, filename="output.pdf", dpi=300) # Qt renderer (default, recommended)
118mpl_render(sketch, filename="output.pdf") # Matplotlib fallback (deprecated, text scaling issues)
119```
120
121Supported formats: `.pdf`, `.png`, `.jpg`, `.svg`
122
123## Tips for the Agent
124
1251. Always define `S = 30.0` as the scale factor
1262. Place beams first, then supports at endpoints, then loads
1273. Use LaTeX for annotations: `r"$F$"`, `r"$M_0$"`, `r"$\ell$"`
1284. For detailed API signatures, see `references/api_reference.md`
1295. The `render()` function requires a filename — it does not display interactively
1306. Do **not** use `mpl_render()` — it is deprecated due to text scaling issues. Always use `render()`.
131
132## External Endpoints
133
134This skill makes **no network requests**. All processing is done locally.
135
136## Security & Privacy
137
138- **No data leaves your machine.** The skill only reads local JSON files and writes local image/PDF output.
139- No API keys or credentials are required.
140- No telemetry or analytics.
141- The helper script (`scripts/generate_sketch.py`) only reads the input file specified by the user and writes to the specified output path.
142
143## Trust Statement
144
145This skill is developed and maintained by [MatthiasHBusch](https://github.com/MatthiasHBusch). The source code is fully open under the MIT license. All functionality runs locally with no external dependencies beyond standard Python packages (matplotlib, PyQt5).