executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
qcadUse when editing DXF files with a professional open-source 2D CAD application — CAM output, part libraries, isometric projection. QCAD: open-source 2D CAD with DXF as native format, scriptable via ECMAScript.
Independent GitHub snapshot · Automated classification · Original documentation governs
name: qcad description: "Use when editing DXF files with a professional open-source 2D CAD application — CAM output, part libraries, isometric projection. QCAD: open-source 2D CAD with DXF as native format, scriptable via ECMAScript." tags:
项目地址: https://github.com/qcad/qcad
官方文档: https://qcad.org/en/qcad-documentation
API 参考: https://api.qcad.org/
许可证: GPL-3.0(社区版);Pro 版商业许可
最新稳定版: 3.33.1(截至2026年9月,GitHub tag
v3.33.1.0,见 https://qcad.org/en/download)
QCAD 由两部分组成:
核心能力:
qcad、dwg2dxf、dxf2pdf、dxf2bmp 等# 二进制:<https://qcad.org/en/download>
# Linux 自带:sudo apt install qcad
# 命令行
qcad # 启动 GUI
qcad -no-gui -autostart script.js # 无界面运行脚本
将 ODA File Converter(免费)放在 PATH 中以支持 DWG。
qcad-installation/
├── qcad # 主程序
├── plugins/ # 二进制插件
├── scripts/ # 脚本扩展(自带 + 用户)
│ ├── Draw/
│ ├── Modify/
│ ├── File/
│ └── Examples/
└── doc/api/ # API 文档(同 api.qcad.org)
用户脚本目录:$HOME/.qcad/scripts(Linux)或对应路径。
include("scripts/EAction.js");
function MyLine(guiAction) { EAction.call(this, guiAction); }
MyLine.prototype = new EAction();
MyLine.prototype.beginEvent = function() {
EAction.prototype.beginEvent.call(this);
var doc = this.getDocument();
var line = new RLineEntity(doc, new RLineData(
new RVector(0, 0), new RVector(100, 50)));
var op = new RAddObjectsOperation();
op.addObject(line);
doc.applyOperation(op);
this.terminate();
};
将文件保存为 ~/.qcad/scripts/MyLine.js 并通过 Misc → Run script,或在控制台调用。
var doc = getDocument();
print(doc.getEntityIdsByType(RS.EntityLine).length);
// 添加圆
var circle = new RCircleEntity(doc, new RCircleData(new RVector(0,0), 10));
var op = new RAddObjectsOperation();
op.addObject(circle);
doc.applyOperation(op);
# DXF → PDF
dxf2pdf -o out.pdf input.dxf
# DXF → SVG
dxf2svg -o out.svg input.dxf
# DWG → DXF(需 ODA File Converter 或 LibreDWG)
dwg2dxf -outversion=2018 input.dwg
# DXF → BMP / PNG
dxf2bmp -a -o out.png input.dxf
// batch_export.js
var fileList = ["a.dxf", "b.dxf", "c.dxf"];
for (var i = 0; i < fileList.length; ++i) {
var doc = new RDocument(new RMemoryStorage(), createSpatialIndex());
var fi = new RFileImporterRegistry();
var importer = fi.getFileImporterFromFileName(fileList[i], doc);
importer.importFile(fileList[i]);
// 导出 PDF
var exporter = new RPdfExporter(doc);
exporter.exportToFile("out_" + i + ".pdf");
}
运行:
qcad -no-gui -autostart batch_export.js
var doc = getDocument();
// 遍历所有实体
var ids = doc.queryAllEntities();
for (var i = 0; i < ids.length; ++i) {
var e = doc.queryEntity(ids[i]);
if (isLineEntity(e))
print("LINE", e.getStartPoint(), "→", e.getEndPoint());
}
// 修改图层
var layer = new RLayer(doc, "WALL", false, false,
new RColor("#ff0000"), doc.getLinetypeId("CONTINUOUS"), RLineweight.Weight030);
var op = new RAddObjectsOperation();
op.addObject(layer);
doc.applyOperation(op);
| 操作 | API |
|---|---|
| 添加 | RAddObjectsOperation |
| 修改 | RModifyObjectsOperation |
| 删除 | RDeleteObjectsOperation |
| 平移/旋转/缩放 | RModifyObjectsOperation + RTransform* |
| 选择集 | getDocumentInterface().getStorage().queryAllSelectedEntities() |
| 块 | RBlockReferenceEntity + RBlock |
RGraphicsSceneQt + RPrinterRDocument + RMemoryStorage 处理无 UI 转换RAddObjectsOperation.addObject(obj, false) 不立即更新空间索引applyOperation| 问题 | 解决 |
|---|---|
| DWG 打不开 | 安装 ODA File Converter 并在 Preferences → File I/O 配置 |
| 字体缺失 | 复制 .shx/.ttf 到 fonts/ 目录或安装到系统 |
| 中文显示乱 | 设置图层使用支持 CJK 的字体(如 simhei) |
| 脚本路径错 | 使用绝对路径或 documentInterface.getDocument() |
qcad -no-gui -autostart script.js 无界面运行。ECMAScript 脚本遵循「获取文档 → 构建操作(RAddObjectsOperation 等)→ applyOperation」的模式。DWG 文件需 ODA File Converter 支持。include("scripts/EAction.js") 继承 EAction;③ 批量操作使用 RAddObjectsOperation.addObject(obj, false) 不立即更新空间索引,最后统一 applyOperation;④ 中文字体使用 CJK 支持的 TTF(如 simhei)。var line = new RLineEntity(doc, new RLineData(new RVector(0,0), new RVector(100,50))) → var op = new RAddObjectsOperation() → op.addObject(line) → doc.applyOperation(op)。CLI 转换:dxf2pdf -o out.pdf input.dxf / dxf2svg -o out.svg input.dxf。.js 脚本文件,include("scripts/EAction.js") 引入基础类EAction,在 beginEvent() 中通过 this.getDocument() 获取文档RLineEntity/RCircleEntity 等实体对象RAddObjectsOperation 批量添加实体doc.applyOperation(op) 提交操作Misc → Run script 运行,或 qcad -no-gui -autostart script.js 无界面执行dxf2pdf -o out.pdf input.dxf DXF 转 PDFdxf2svg -o out.svg input.dxf DXF 转 SVGdxf2bmp -a -o out.png input.dxf DXF 转 PNG 位图dwg2dxf -outversion=2018 input.dwg DWG 转 DXF(需 ODA File Converter)