Read and edit PDFs: extract text and tables, merge, split, rotate, and fill forms.
ANanthropics/skills181k1,119 new stars in the last 7 days
AutoCAD 自动化技能。用于让 Codex/Claude 在 Windows 上通过 Python COM/ActiveX 直连本机 AutoCAD 进行二维绘图、图层/文字/标注/块处理、DWG/DXF/PDF 导出、批量修改、工程图自检,以及在 COM 不足时切换到 AutoLISP/SCR 或 AutoCAD .NET 插件路线;当用户提到 AutoCAD、CAD、DWG、DXF、画图、出图、图层、标注、块、批量改图、AutoLISP、ObjectARX、.NET 插件、Codex 接入 CAD 软件时都应优先使用。
本目录作为
solidworks-automation-skill的 AutoCAD/DWG 子技能使用。父技能负责 SolidWorks 建模、装配、工程图和三维导出;本子技能负责 AutoCAD 二维 DWG/DXF 绘制、批量改图、线稿矢量化、出图预览和图纸自检。涉及 SolidWorks 原生零件/装配体建模时回到父技能,涉及 AutoCAD 图纸或 DWG/DXF 时读取本子技能。
让代理在本机 Windows 桌面环境中可靠控制 AutoCAD,而不是每次凭记忆临时拼命令。默认路线是 Python + COM/ActiveX,但原生写入必须先通过 capabilities.yaml 门禁和本机真机回归;当前 AutoCAD 2024 的 Documents/Layers/SelectionSets 动态代理不稳定,因此 COM 原生 DWG 绘图按 not_implemented 处理。DXF 无头读取、预览和结构审查可直接使用。AutoCAD 2024 .NET 白名单后端已连续通过真实 DWG 保存重开、PDF/PNG 和实体/图层/尺寸回归,运行时证据完整时为 verified;只允许固定命令,不得推广成任意代码执行。
使用本技能处理:
.scr 命令脚本或 C# AutoCAD .NET 插件。不要把本技能用于纯渲染效果图、BIM/Revit 模型、机械 STEP-first 建模、CAM 刀路或工程认证结论;这些需求优先转给相应 CAD、BIM、仿真或制造流程。
AutoCAD.Application COM ProgID。Z=0。缺少版本、单位、图纸标准、输出路径或是否允许覆盖时,先做一次简短确认。简单草图可以直接假设毫米、ModelSpace、新建 DWG,并在结果中说明。
执行 AutoCAD 自动化前先运行:
python subskills\autocad-automation\scripts\acad_preflight.py
如果用户允许自动启动 AutoCAD:
python subskills\autocad-automation\scripts\acad_preflight.py --launch
自检失败时:
pywin32:提示用户安装 python -m pip install pywin32,得到明确同意后再安装。acad_preflight.py 确认 Python COM 和 AutoCAD 状态。references/api-lookup.md,再查 Autodesk 官方文档或可信 GitHub 示例;不要猜长参数、枚举值和命令行为。scripts/acad_draw.py 的 JSON 输入;复杂逻辑用 scripts/acad_session.py 组合 COM 调用。scripts/acad_review.py 统计实体、图层、包围盒和目标文件;再运行 scripts/acad_preview.py 导出 AutoCAD 原生 BMP/PNG 预览,并用图片查看工具做视觉审查。窗口截图可作为补充,但若被其它窗口遮挡,不可作为通过依据。
若输入是 DXF 且只需无头只读检查,可先运行 scripts/acad_headless.py;它不支持 DWG 写入,最终 DWG/PDF 仍须走 AutoCAD COM。references/troubleshooting.md 或脚本。当用户要求“严格遵守规范”“中国人正常喜欢的格式”“国标图纸”“加工图”“3D打印开孔”或类似机械制图交付时,必须按机械图纸而不是示意图处理:
4×φ3.4、7×4×30、2×φ13.5 而没有相对基准边、中心距、节距或高度定位,视为未完成。AcDbRotatedDimension,不要手画尺寸线冒充尺寸。简单任务可让 Codex 生成一个绘图 JSON,然后调用:
python subskills\autocad-automation\scripts\acad_draw.py `
--input C:\temp\plate_plan.json `
--output C:\temp\plate.dwg `
--new
这个入口默认是“可见逐步绘图”模式:会先打开或切到 AutoCAD,再一点点把图元画出来。只有批量任务、回放太慢或用户明确要求快时,才加 --fast:
python subskills\autocad-automation\scripts\acad_draw.py `
--input C:\temp\batch_plan.json `
--output C:\temp\batch.dwg `
--new `
--fast
JSON 结构示例:
{
"units": "mm",
"live_preview": true,
"live_zoom_every": 6,
"layers": [
{"name": "OUTLINE", "color": 7},
{"name": "CENTER", "color": 1},
{"name": "TEXT", "color": 3}
],
"entities": [
{"type": "rectangle", "origin": [0, 0], "width": 120, "height": 80, "layer": "OUTLINE"},
{"type": "circle", "center": [20, 20, 0], "radius": 4.5, "layer": "CENTER"},
{"type": "text", "text": "MOUNTING PLATE", "point": [8, 88, 0], "height": 5, "layer": "TEXT"}
]
}
复杂任务使用 Python:
import sys
sys.path.insert(0, r"subskills\autocad-automation\scripts")
from acad_session import AutoCADSession
session = AutoCADSession(create_if_missing=True, visible=True).connect()
session.new_document()
session.activate_window()
session.create_layer("OUTLINE", color=7)
session.add_rectangle((0, 0), width=120, height=80, layer="OUTLINE")
session.live_update(step_delay_s=0.15, zoom=True)
session.save_as(r"C:\temp\plate.dwg")
| 需求 | 首选路线 | 说明 |
|---|---|---|
| 快速绘制、改图、批量检查 | Python COM/ActiveX | 本技能默认路线,可由 Codex 直接通过 shell 执行 |
| 执行 AutoCAD 命令、调用已有命令习惯 | SendCommand / .scr / AutoLISP | 命令可能异步,必须保存和复核结果 |
| 大量数据库事务、复杂选择过滤、插件菜单 | AutoCAD .NET | 适合 C# 插件,按官方 .NET Developer Guide 做事务和文档锁 |
| 高性能原生扩展、深层数据库/图形系统 | ObjectARX C++ | 成本高,版本绑定强,先确认必要性 |
| 云端批处理 DWG | APS Design Automation | 适合无桌面、批量生产或 CI,但需要 Autodesk APS 凭据 |
0 层。BODY_OUTLINE、JERSEY_OUTLINE、PORTRAIT_OUTLINE、OUTER_GUIDE、CONSTRUCTION、FACE_FEATURES、LOGO_GEOMETRY、WATER_SPLASH、JERSEY_STRIPE、TEXT_LOGO、TEXT_BRAND 等构造/增强层,最终保存、预览和评分前必须删除、冻结、关闭或设为不打印,并在预览和图层统计中确认不可见、实体数为 0。SendCommand 是最后手段;优先调用对象模型方法,命令脚本要用 _.COMMAND 形式降低界面语言影响。优先来源:
pyautocad 等成熟开源项目可借鉴坐标、迭代和 COM 封装模式,但不要复制不明许可证代码。当资料冲突时,以目标 AutoCAD 版本的官方文档和本机实测结果为准。
按需读取,不要一次塞满上下文:
references/api-lookup.md:官方文档、GitHub 示例和 API 查证路线。references/engineering-patterns.md:资深工程师绘图、图层、单位、块、标注和批处理经验。references/troubleshooting.md:COM、AutoCAD 会话、SendCommand、保存导出和版本问题排查。完成 AutoCAD 操作后,最终回复要包含:
Read and edit PDFs: extract text and tables, merge, split, rotate, and fill forms.
ANanthropics/skills181k1,119 new stars in the last 7 days
Create posters and visual art as PNG or PDF, guided by a design philosophy.
ANanthropics/skills181k1,119 new stars in the last 7 days
Create and edit Word docs with TOC, page numbers, headers and more.
ANanthropics/skills181k1,119 new stars in the last 7 days
Co-write specs, proposals and decision docs through a structured, iterative workflow.
ANanthropics/skills181k1,119 new stars in the last 7 days
Read and edit spreadsheets: add columns, compute formulas, format, and clean messy data.
ANanthropics/skills181k1,119 new stars in the last 7 days
Create and edit slide decks, generate slides from templates, and extract text.
ANanthropics/skills181k1,119 new stars in the last 7 days