乐于分享
好东西不私藏

CAD 插件教程2|一键绘制槽铝 LSP 命令分享

CAD 插件教程2|一键绘制槽铝 LSP 命令分享

接上篇角铝绘图命令,今天继续分享AutoCAD 槽铝快速绘制 LSP 插件,输入简单参数即可一键生成图形,提升绘图效率。

一、插件使用步骤

  1. 保存脚本文件

将下文完整源码复制,粘贴到记事本中,文件另存为 LC.LSP(编码选择ANSI,后缀必须为 .lsp)。

  1. CAD 
    加载插件

打开 AutoCAD,在命令行输入 APPLOAD并回车,在弹出窗口选中 LC.LSP 完成加载。

加载成功后,命令行提示:LC.LSP successfully loaded.

  1. 调用绘图命令

命令行输入自定义命令 LC,根据提示依次输入参数:

  • 槽宽
  • 槽高
  • 型材厚度

最后指定图形底边中点,即可自动生成槽铝轮廓。

补充:脚本自带旋转功能,绘制完成后可直接拖动鼠标调整角度。

二、LSP 完整源码

lsp

; LC.lspCAD一键绘制槽铝

(defun c:lc ( / ds1 ds2 ds4 ds5 pt pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 osn)

; 获取用户输入参数

(setq ds1 (getdist "\n请输入槽宽:"))

(setq ds4 (getdist "\n请输入槽高:"))

(if (null ds4) (setq ds4 ds1))

(setq ds2 (getdist "\n请输入型材厚度:"))

(setq ds5 (- ds4 ds2))

(setq pt (getpoint "\n请指定槽铝底边中点:"))

; 计算各顶点坐标

(setq pt1 (list (- (nth 0 pt) (* 0.5 ds1)) (nth 1 pt)))

(setq pt2 (list (+ (nth 0 pt1) ds1) (nth 1 pt1)))

(setq pt3 (list (nth 0 pt2) (+ (nth 1 pt2) ds4)))

(setq pt4 (list (+ (nth 0 pt1) ds2) (+ (nth 1 pt1) ds2)))

(setq pt5 (list (nth 0 pt4) (+ (nth 1 pt4) ds5)))

(setq pt6 (list (nth 0 pt1) (nth 1 pt5)))

(setq pt7 (list (- (nth 0 pt3) ds2) (nth 1 pt3)))

(setq pt8 (list (nth 0 pt7) (- (nth 1 pt7) ds5)))

; 临时关闭对象捕捉,避免绘图偏移

(setq osn (getvar "osmode"))

(setvar "osmode" 0)

; 多段线绘制槽铝轮廓

(command "pline" pt1 pt2 pt3 pt7 pt8 pt4 pt5 pt6 "c")

; 恢复原有捕捉设置

(setvar "osmode" osn)

; 图形旋转(修复原代码报错问题)

(command "rotate" (entlast) "" pt pause)

(princ)

)

三、常见问题说明

  1. 加载失败:检查文件后缀是否为     .lsp,记事本保存编码改为ANSI;
  2. 输入参数后无图形:确认坐标点拾取正常,不要中途按 ESC 终止命令;
  3. 命令不识别:重新执行     APPLOAD 加载文件。

回首页,搜索你想要的文档

在首页搜索框输入关键词,快速定位资料

文库首页搜索指引 立即搜索

相关学习资料