MechanicsSketches Skill
You can generate engineering mechanics sketches programmatically using the MechanicsSketches Python library.
Setup
Install the library via pip:
CODEBLOCK0
Or install dependencies manually and add to PYTHONPATH:
CODEBLOCK1
Quick Start — Writing a Script
Create a Python script that builds a sketch and renders it:
CODEBLOCK2
Then run: INLINECODE1
Quick Start — Using the Helper Script
Alternatively, use the bundled helper to render from JSON:
CODEBLOCK3
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 |
|---|
| INLINECODE5 | Rectangular beam A→B | Endpoints, scale |
| INLINECODE6 |
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$") - INLINECODE20 — relative font size (default 1.0)
- INLINECODE21 ,
offsety — label position offset - INLINECODE23 — rotate label with component (default False)
Primitives
For custom shapes, use:
- - INLINECODE24
- INLINECODE25
- INLINECODE26
- INLINECODE27
- INLINECODE28
- INLINECODE29
Add to sketch via add_to_sketch(sketch, primitive).
Transformations
- -
translate(obj, dx, dy) — move by offset - INLINECODE32 — rotate around point
- INLINECODE33 — scale from center
All return new objects (non-destructive). Can be chained.
Rendering
CODEBLOCK4
Supported formats: .pdf, .png, .jpg, INLINECODE37
Tips for the Agent
- 1. 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$", INLINECODE41 - For detailed API signatures, see INLINECODE42
- 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).
MechanicsSketches 技能
您可以使用 MechanicsSketches Python 库以编程方式生成工程力学草图。
安装
通过 pip 安装库:
bash
pip install git+https://github.com/MatthiasHBusch/MechanicsSketches.git
或者手动安装依赖项并添加到 PYTHONPATH:
bash
pip install matplotlib PyQt5
export PYTHONPATH=/path/to/parent/of/MechanicsSketches:$PYTHONPATH
快速入门 — 编写脚本
创建一个构建草图并渲染的 Python 脚本:
python
from MechanicsSketches import *
import os
sketch = create_sketch(My Sketch)
S = 30.0 # 比例因子(推荐:20-40)
添加组件
add
beam(sketch, ax=0, ay=0, bx=10*S, by=0, scalefactor=S)
add
pinnedsupport(sketch, cx=0, cy=0, angle
deg=0, scalefactor=S)
add
rollersupport(sketch, cx=10*S, cy=0, angle
deg=0, scalefactor=S)
add
force(sketch, cx=5*S, cy=0, angledeg=0, scale_factor=S, annotation=r$F$)
渲染
script_dir = os.path.dirname(os.path.abspath(
file))
render(sketch, filename=os.path.join(script_dir, output.pdf), dpi=300)
然后运行:python my_sketch.py
快速入门 — 使用辅助脚本
或者,使用捆绑的辅助脚本从 JSON 渲染:
bash
python scripts/generate_sketch.py input.json output.pdf
关键概念
比例因子(S)
所有位置和尺寸应为 S 的倍数(通常为 30.0)。这可以保持各组件之间的比例一致。
角度约定
- - angle_deg=0 → 默认方向(支撑/力朝上,尺寸水平)
- 角度以度为单位逆时针旋转
可用组件
| 函数 | 描述 | 关键参数 |
|---|
| addbeam(sketch, ax, ay, bx, by, scalefactor) | 矩形梁 A→B | 端点,比例 |
| addtruss(sketch, ax, ay, bx, by, scalefactor) |
线杆件 A→B | 端点,比例 |
| add
pinnedsupport(sketch, cx, cy, angle
deg, scalefactor) | 固定位置支撑(三角形) | 中心,角度,比例 |
| add
rollersupport(sketch, cx, cy, angle
deg, scalefactor) | 滑动支撑 | 中心,角度,比例 |
| add
fixedsupport(sketch, cx, cy, angle
deg, scalefactor) | 固定墙支撑 | 中心,角度,比例 |
| add
hinge(sketch, cx, cy, scalefactor) | 铰接圆 | 中心,比例 |
| add
force(sketch, cx, cy, angledeg, scale_factor, annotation, ...) | 力箭头 | 中心,角度,比例,标签 |
| add
moment(sketch, cx, cy, angledeg, scale_factor, annotation, ...) | 弯曲力矩箭头 | 中心,角度,比例,标签 |
| add
dimensionarrow(sketch, cx, cy, length, angle
deg, scalefactor, annotation, ...) | 双头尺寸箭头 | 中心,长度,角度,比例,标签 |
| add
dimensionthickness(sketch, cx, cy, thickness, angle
deg, scalefactor, annotation, ...) | 内向尺寸箭头 | 中心,厚度,角度,比例,标签 |
| add
coordinatesystem(sketch, cx, cy, angle
deg, scalefactor, ax1, ax2, ax3, ...) | x-y-z 轴 | 中心,角度,比例,轴标签 |
| add_text(sketch, x, y, text, fontsize, name, rotation) | 文本注释 | 位置,文本,字体大小 |
注释参数
力、力矩和尺寸函数接受:
- - annotation — LaTeX 字符串(例如 r$F$,r$MA$)
- fontsizescale — 相对字体大小(默认 1.0)
- offsetx,offsety — 标签位置偏移
- rotate_annotation — 标签随组件旋转(默认 False)
基本图元
对于自定义形状,使用:
- - makeline(x0, y0, x1, y1, linewidth, layer, edgecolor)
- makecircle(x, y, r, linewidth, layer, facecolor, edgecolor)
- makepolygon(points, linewidth, layer, facecolor, edgecolor)
- makearc(x, y, width, height, theta1, theta2, angle, linewidth, layer)
- maketext(x, y, text, fontsize, layer, color, ha, va, rotation)
- makerectangle(x0, y0, x1, y1, ...)
通过 addtosketch(sketch, primitive) 添加到草图。
变换
- - translate(obj, dx, dy) — 按偏移移动
- rotate(obj, cx, cy, angle_deg) — 绕点旋转
- scale(obj, cx, cy, factor) — 从中心缩放
所有操作返回新对象(非破坏性)。可以链式调用。
渲染
python
render(sketch, filename=output.pdf, dpi=300) # Qt 渲染器(默认,推荐)
mpl_render(sketch, filename=output.pdf) # Matplotlib 回退(已弃用,文本缩放问题)
支持的格式:.pdf,.png,.jpg,.svg
给代理的提示
- 1. 始终定义 S = 30.0 作为比例因子
- 先放置梁,然后在端点放置支撑,最后放置荷载
- 使用 LaTeX 进行注释:r$F$,r$M0$,r$\ell$
- 有关详细的 API 签名,请参见 references/apireference.md
- render() 函数需要文件名——它不会交互式显示
- 不要使用 mpl_render()——由于文本缩放问题,它已被弃用。始终使用 render()。
外部端点
此技能不进行任何网络请求。所有处理均在本地完成。
安全与隐私
- - 没有数据离开您的机器。 该技能仅读取本地 JSON 文件并写入本地图像/PDF 输出。
- 不需要 API 密钥或凭据。
- 没有遥测或分析。
- 辅助脚本(scripts/generate_sketch.py)仅读取用户指定的输入文件并写入指定的输出路径。
信任声明
此技能由 MatthiasHBusch 开发和维护。源代码在 MIT 许可下完全开源。所有功能在本地运行,除标准 Python 包(matplotlib,PyQt5)外没有外部依赖。