Skills Plugins MCP Prompt Model 博客 我的中心

cad-automation

CAD自动化绘图skill,内置完整的AutoCAD二次开发知识体系。支持通过Python(pyautocad/win32com)/AutoLISP/C#/VBA连接AutoCAD进行自动化绘图、编辑、图层管理、标注、块与属性、三维建模、批量处理、文件转换等。也涵盖国产中望CAD/浩辰CAD的兼容性。

DeepseekModel Curated skill Quality Good · 64 v1.0.0

Get

https://deepseekmodel.com/api/download.php?id=delancy827-cad-skills-cad-automation-skill-md&format=skill
Download .skill Standard format with system_prompt and model_config, ready for any agent framework
The actual content of the system_prompt field in the .skill file.
name cad-automation description CAD自动化绘图skill,内置完整的AutoCAD二次开发知识体系。支持通过Python(pyautocad/win32com)/AutoLISP/C#/VBA连接AutoCAD进行自动化绘图、编辑、图层管理、标注、块与属性、三维建模、批量处理、文件转换等。也涵盖国产中望CAD/浩辰CAD的兼容性。 category engineering-cad version 1.1.0 author Delancy CAD 自动化绘图 Skill(优化版) 本skill提供AutoCAD自动化绘图的完整知识体系,涵盖Python COM自动化、AutoLISP插件开发、国产CAD兼容等核心内容。 0. 2026-06-11 优化版使用原则 本版把 CAD 自动化从“只会调用 AutoCAD”升级为“三栈协同”: 场景 首选技术 原因 降级方案 已安装 AutoCAD、要直接生成 DWG win32com / pyautocad 可调用真实 AutoCAD,适合出 DWG、标注、图层、打印 SendCommand / SCR 没有 CAD 软件、要稳定生成交换文件 ezdxf 离线生成 DXF,适合 CI、服务器、批量草图 生成 SVG/JSON 几何清单 参数化 3D、模具/夹具/结构件建模 CadQuery / FreeCAD 适合尺寸驱动和 STEP/STL 输出 先生成 2D 总图,再转 3D 国产 CAD 兼容 COM + 英文命令 + DXF 中望/浩辰对 COM 和 DXF 兼容度通常较高 AutoLISP 执行铁律 先判断环境: AutoCAD.Application 能连接则走 COM,不能连接则走离线 DXF。 模型空间永远按 1:1、毫米单位绘制;图纸空间只处理视口和出图比例。 每次自动绘图都要创建标准图层、锁定 WCS、清理选择集、执行 AUDIT/PURGE/ZOOM E/REGENALL 。 输出前至少做 L3 验证:对象数量、关键图层、关键几何尺寸、文字/标注存在性。 使用外部开源项目的思路、API 或示例时,在交付包中保留 ATTRIBUTION.md ,注明来源、许可证和本项目的使用方式。 外部开源资料吸收范围 本 skill 只吸收公开文档中的工程方法,不复制大段源代码。参考项目: 项目 作用 许可证 使用方式 reclosedev/pyautocad AutoCAD ActiveX 自动化封装、坐标与对象遍历思路 BSD-2-Clause 作为 COM 自动化路线参考 mozman/ezdxf 离线 DXF 创建/读写/修改 MIT 作为无 AutoCAD 环境的 fallback CadQuery/cadquery Python 参数化 3D CAD Apache-2.0 作为 3D 参数化建模路线参考 开源CAD自动化项目 行业最佳实践参考 多种 作为技术路线与接口设计参考 ⚠️ Python AutoCAD COM 关键踩坑 环境 AutoCAD 2020+ (中文版), Python 3.10+ + pyautocad/pywin32, Windows 11 连接方式 方式 结果 pyautocad.Autocad(create_if_not_exists=True) ✅ 推荐,自动处理COM win32com.client.Dispatch("AutoCAD.Application") ✅ 底层连接 win32com.client.GetActiveObject("AutoCAD.Application") ✅ 连接已运行的实例 win32com.client.Dispatch("AutoCAD.Application.24") ✅ 指定版本(2021=24,2022=24.1,2023=24.2,2024=24.3) 核心踩坑 pyautocad 安全数组 : 坐标必须用 APoint(x,y,z) 包装 COM对象生命周期 : GetActiveObject 失败则需 Dispatch 单位 : AutoCAD内部使用绘图单位,默认公制mm 中文命令 : 用 acad.doc.SendCommand("_LINE ") 带下划线前缀 选择集 : acad.doc.SelectionSets 使用后必须 Delete() ,否则累积报错 中望/浩辰兼容 : pyautocad同样支持(COM接口兼容),但部分VLAX函数需要适配 一、AutoCAD 基础知识 1.1 AutoCAD 概述 AutoCAD是Autodesk公司开发的通用CAD软件,支持建筑、机械、电气、土木等领域。 1.2 坐标系 WCS (世界坐标系) : 绝对坐标系,原点固定 UCS (用户坐标系) : 可自定义原点和方向 极坐标 : @距离<角度 (如 @100<45 ) 相对坐标 : @x,y (如 @50,30 ) 1.3 文件类型 类型 扩展名 说明 图形文件 .dwg 标准图形文件 交换格式 .dxf 文本/二进制交换格式 模板 .dwt 含预设样式模板 标准 .dws 图层/标注/文字标准 脚本 .scr 批量命令脚本 线型 .lin 自定义线型定义 填充 .pat 自定义填充图案 1.4 常用API对象层次 AutoCAD.Application ├── ActiveDocument (Document) │ ├── ModelSpace (模型空间) │ ├── PaperSpace (图纸空间) │ ├── Layers (图层集合) │ ├── Linetypes (线型集合) │ ├── TextStyles (文字样式) │ ├── DimStyles (标注样式) │ ├── Blocks (块集合) │ ├── SelectionSets (选择集) │ ├── Groups (组集合) │ └── Utility (角度/距离/坐标工具) ├── Documents ├── Preferences (系统配置) └── MenuGroups (菜单组) 二、绘图命令 (Drawing) 2.1 基本图元 from pyautocad import Autocad, APoint, aDouble acad = Autocad(create_if_not_exists= True ) # 直线 line = acad.model.AddLine(APoint( 0 , 0 , 0 ), APoint( 100 , 50 , 0 )) # 圆 circle = acad.model.AddCircle(APoint( 50 , 50 , 0 ), 30 ) # 圆弧 (center, radius, start_angle弧度, end_angle弧度) arc = acad.model.AddArc(APoint( 50 , 50 , 0 ), 30 , 0 , 3.14159 ) # 轻量多段线 (2D, 推荐) pts = aDouble( 0 , 0 , 100 , 0 , 100 , 50 , 50 , 50 ) # x,y交替 pline = acad.model.AddLightWeightPolyline(pts) pline.Closed = True pline.Color = 1 # 红色 # 椭圆 ellipse = acad.model.AddEllipse(APoint( 50 , 50 , 0 ), APoint( 30 , 0 , 0 ), 0.5 ) # 样条曲线 fit_pts = aDouble( 0 , 0 , 0 , 20 , 30 , 0 , 50 , 10 , 0 , 80 , 60 , 0 , 100 , 0 , 0 ) spline = acad.model.AddSpline(fit_pts, aDouble( 1 , 1 , 0 ), aDouble( 1 , 0 , 0 )) # 文字 text = acad.model.AddText( "设计说明" , APoint( 10 , 10 , 0 ), 5 ) mtext = acad.model.AddMText(APoint( 10 , 10 , 0 ), 50 , "多行\\P文字" ) # 点 point = acad.model.AddPoint(APoint( 50 , 50 , 0 )) 2.2 填充 (Hatch) outer_loop = [pline] hatch = acad.model.AddHatch( 0 , "ANSI31" , True ) hatch.AppendOuterLoop(outer_loop) hatch.Evaluate() hatch.PatternScale = 2.0 hatch.PatternAngle = 0.785 # 45° hatch.Color = 3 2.3 SendCommand 方式 (兼容性最好) acad.doc.SendCommand( "_CIRCLE 50,50 30 " ) acad.doc.SendCommand( "_LINE 0,0 100,50 \n" ) # \n = 回车, 空格 = 结束当前输入 三、编辑命令 (Modify) 3.1 基本编辑 # 移动 obj.Move(APoint( 0 , 0 , 0 ), APoint( 50 , 0 , 0 )) # 复制 new_obj = obj.Copy() new_obj.Move(APoint( 0 , 0 , 0 ), APoint( 100 , 0 , 0 )) # 旋转 (基点, 角度弧度) obj.Rotate(APoint( 0 , 0 , 0 ), 1.5708 ) # 90° # 缩放 (基点, 比例因子) obj.ScaleEntity(APoint( 0 , 0 , 0 ), 2.0 ) # 镜像 (镜像线两点) obj.Mirror(APoint( 0 , 0 , 0 ), APoint( 0 , 100 , 0 )) # 偏移 obj.Offset( 10 ) # 返回数组(可能多个结果) # 阵列 (矩形) obj.ArrayRectangular( 3 , 2 , 1 , 100 , 50 , 0 ) # rows,cols,levels,row_sp,col_sp,level_sp 3.2 通过SendCommand操作 acad.doc.SendCommand( "_MOVE\n" ) # 移动 acad.doc.SendCommand( "_COPY\n" ) # 复制 acad.doc.SendCommand( "_ROTATE\n" ) # 旋转 acad.doc.SendCommand( "_SCALE\n" ) # 缩放 acad.doc.SendCommand( "_MIRROR\n" ) # 镜像 acad.doc.SendCommand( "_OFFSET 10\n" ) # 偏移 acad.doc.SendCommand( "_TRIM\n" ) # 修剪 acad.doc.SendCommand( "_EXTEND\n" ) # 延伸 acad.doc.SendCommand( "_FILLET R 5\n_FILLET\n" ) # 圆角R5 acad.doc.SendCommand( "_CHAMFER D 3 3\n_CHAMFER\n" ) # 倒角3x3 四、图层管理 (Layers) # 创建图层 layer = acad.doc.Layers.Add( "WALL" ) layer.Color = 1 # 红色 (ACI色号) layer.Linetype = "Continuous" # 设置当前图层 acad.doc.ActiveLayer = acad.doc.Layers( "WALL" ) # 遍历所有图层 for layer in acad.doc.Layers: print ( f" {layer.Name} : color= {layer.Color} , linetype= {layer.Linetype} " ) # 锁定/冻结/关闭 ref = acad.doc.Layers( "WALL" ) ref.Lock = True # 锁定 ref.Freeze = False # 冻结 ref.LayerOn = True # 开关 # 修改对象图层 line.Layer = "DIM" # 批量修改图层 (SendCommand) acad.doc.SendCommand( "_LAYMCH\n" ) # 图层匹配 acad.doc.SendCommand( "_LAYISO\n" ) # 图层隔离 acad.doc.SendCommand( "_LAYUNISO\n" ) # 取消隔离 ACI常用色号 色号 颜色 适用 1 红 标注/重点 2 黄 中心线 3 绿 辅助线 4 青 文字 5 蓝 轮廓 6 品红 剖面 7 白/黑 默认 8 灰 参考线 五、标注与文字 (Dimensions & Text) 5.1 标注 p1 = APoint( 0 , 0 , 0 ) p2 = APoint( 100 , 0 , 0 ) text_pos = APoint( 50 , - 20 , 0 ) # 线性标注 dim = acad.model.AddDimAligned(p1, p2, text_pos) # 旋转标注 dim = acad.model.AddDimRotated(p1, p2, text_pos, 0 ) # 半径/直径标注 dim_rad = acad.model.AddDimRadial(APoint( 50 , 50 , 0 ), circle, 10 ) # leader_length dim_dia = acad.model.AddDimDiametric(APoint( 50 , 50 , 0 ), circle, 10 ) # 角度标注 dim_ang = acad.model.AddDimAngular(APoint( 0 , 0 , 0 ), p1, p2, APoint( 30 , 30 , 0 )) # 坐标标注 dim_ord = acad.model.AddDimOrdinate(APoint( 50 , 50 , 0 ), APoint( 50 , 0 , 0 ), True ) # X坐标 # 标注样式 dim_style = acad.doc.DimStyles.Add( "GB_DIM" ) dim.TextHeight = 3.5 # 字高 dim.ArrowheadSize = 2.5 # 箭头大小 dim.DecimalSeparator = "." 5.2 公差与粗糙度 # 公差标注(通过SendCommand兼容性好) acad.doc.SendCommand( "_TOLERANCE\n" ) # 或使用Leader+文字模拟 leader = acad.model.AddLeader(points, annotation, 0 ) 5.3 特殊字符 代码 字符 %%c φ 直径 %%d ° 度 %%p ± 正负号 %%u 下划线开关 \P 换行(MTEXT) 六、块与属性 (Blocks & Attributes) 6.1 块定义 # 创建块定义 block = acad.doc.Blocks.Add(APoint( 0 , 0 , 0 ), "MyBlock" ) # 在块定义中添加对象 block.AddCircle(APoint( 0 , 0 , 0 ), 10 ) block.AddLine(APoint(- 10 , 0 , 0 ), APoint( 10 , 0 , 0 )) # 插入块参照 insert_pt = APoint( 50 , 50 , 0 ) block_ref = acad.model.InsertBlock(insert_pt, "MyBlock" , 1 , 1 , 1 , 0 ) 6.2 带属性的块 # 创建属性定义 att = block.AddAttribute( 5 , # 字高 0 , # 模式(0=无) "标签" , # 提示 APoint( 0 , 15 , 0 ), # 插入点 "TAG" , # 标签 "默认值" # 默认值 ) # 插入后修改属性 for att in block_ref.GetAttributes(): if att.TagString == "TAG" : att.TextString = "零件-001" att.Update() 6.3 外部参照 (Xref) # 附着外部参照 xref = acad.model.AttachExternalReference( "D:/ref/base.dwg" , # 文件路径 "base" , # 块名 APoint( 0 , 0 , 0 ), # 插入点 1 , 1 , 1 , 0 # 比例和旋转 ) 七、选择集与过滤 # 创建选择集 ss = acad.doc.SelectionSets.Add( "SS1" ) # 全选 ss.Select( 5 ) # acSelectionSetAll # 窗口选择 ss.Select( 0 , APoint( 0 , 0 , 0 ), APoint( 100 , 100 , 0 )) # acSelectionSetWindow # 过滤选择 (所有圆,半径>10) import win32com.client ft = win32com.client.VARIANT( 0 , [ 0 , "CIRCLE" , 40 , 10.0 ]) # DXF组码过滤 fd = win32com.client.VARIANT( 0 , [ 0 , ">=" ]) ss.Select( 5 , 0 , 0 , ft, fd) # 遍历选择集 for obj in ss:
Keywords that activate this skill. Click one to copy it.

This skill does not provide trigger words.

The downloaded .skill package contains the following fields.
Field Description
formatFormat tag (skill/v1)
skill_idUnique skill ID
nameSkill name
versionVersion
descriptionDescription
categoryCategories (array)
trigger_wordsTrigger words
tagsTags
sourceSource
source_urlSource URL (this page)
exported_atExported at (set per download)
system_promptSystem prompt body
model_configModel config: provider / model / temperature / max_tokens / top_p
examplesExamples
install_guideImport guide for Coze / Dify / Claude / custom frameworks
The same skill can be exported in different platform formats.
.skill Standard format with system_prompt and model_config, ready for any agent framework Download
.skillpro Enhanced format with scripts, tools, dependencies and hooks Download
.json Plain JSON export with system_prompt and model parameters only Download
Coze Markdown with frontmatter, for Coze platform import Download
Dify Dify DSL, import directly after creating an app Download

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

验证码 --

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。