Step 1:接收用户的流程描述(文字或文件上传)
Step 2:根据描述生成结构化 JSON(nodes + edges),将 JSON 展示给用户确认
Step 3:用户确认后,调用生成脚本:
bash
python3 skills/drawio-generator/scripts/gen.py "图表标题" '{"title":"...","nodes":[...],"edges":[...]}' [类型]
Step 4:交付 .drawio 文件到输出目录,并告知用户:
用 draw.io 打开此文件(网页版 https://app.diagrams.net 或桌面版 App),如需微调请手动调整节点位置后保存。
⚠️ 生成结果非完美,可能存在线条重叠或间距不理想,需要在 draw.io 中手动微调。
输出目录:
/Users/owen/Desktop/drawio-generator/DRAWIO_OUTPUT_DIR 或命令行 --output-dir 自定义json
{
"title": "流程名称",
"type": "flowchart",
"nodes": [
{"id": "0", "type": "start", "label": "开始"},
{"id": "1", "type": "process", "label": "处理步骤"},
{"id": "2", "type": "decision", "label": "判断条件?"},
{"id": "3", "type": "end", "label": "结束"}
],
"edges": [
{"source": "0", "target": "1"},
{"source": "1", "target": "2"},
{"source": "2", "target": "3", "label": "是"},
{"source": "2", "target": "1", "label": "否"}
]
}
type形状start椭圆end椭圆process圆角矩形decision菱形document文档形状data平行四边形
label含义是 / Y条件为真否 / N条件为假空普通顺序流
flowchart | sequence | network | architecture | hierarchy | function | deployment
文件说明scripts/gen.py标准生成脚本(必须使用,禁止直接调用 generator.py)scripts/generator.py底层 XML 生成器(gen.py 内部调用)scripts/parser.py输入解析(txt 直接读取,docx/pdf 需额外安装库)references/drawio-xml-spec.mddraw.io XML 格式规范
依赖说明:
pip install python-docxpip install pdfplumber参数默认值说明CANVAS_WIDTH850画布宽度_LAYER_GAP_Y120层间垂直间距MAIN_X425主轴 X 坐标