明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: yyz123121

封闭区域内一键标注尺寸

[复制链接]
发表于 2025-5-4 17:19:09 | 显示全部楼层
(defun C:NM (/ dxf10 ent p1 p2 p3 s)
    ;; 10组码取点
    (defun dxf10 (e / s)
        (if (setq s
                  (mapcar 'cdr
                          (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e))
                          )
                  )
            (if (= 1 (length s)) (car s) s)
        )
    )
    ;; 获取闭合范围内一点
    (setq p1 (getpoint "\n闭合范围内一点:"))
    ;; 检查 p1 是否为 nil
    (if (not p1)
        (progn
            (princ "\n操作取消,未指定点。")
            (exit)
        )
    )
    ;; 获取闭合多段线实体
    (setq ent (bpoly p1))
    ;; 检查 ent 是否为 nil
    (if (not ent)
        (progn
            (princ "\n无法根据指定点生成闭合多段线实体。")
            (exit)
        )
    )
    ;; 提取点坐标
    (setq s (dxf10 ent))
    ;; 检查 s 是否为 nil
    (if (not s)
        (progn
            (princ "\n未从实体中提取到点坐标。")
            (entdel ent)
            (exit)
        )
    )
    ;; 删除临时实体
    (entdel ent)
    ;; 处理点坐标
    (setq s (cons (last s) s))
    ;; 遍历点坐标进行标注
    (while (and s (cdr s)) ; 确保 s 至少有两个元素
        (setq p1 (car s)
              p2 (cadr s)
              )
        ;; 检查 p1 和 p2 是否有效且不相同
        (if (and p1 p2 (not (equal p1 p2 1e-6))) ; 使用 1e-6 作为容差判断两点是否相同
            (progn
                (setq p3 (polar p2 (+ (* 0.5 pi) (angle p1 p2)) 400))
                (vl-cmdf "DIMLINEAR" "non" p1 "non" p2 "non" p3)
            )
            (princ "\n标注时出现无效点坐标或两点相同,跳过该标注。")
        )
        (setq s (cdr s))
    )
    (princ)
)这样就可以了不报错
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-22 16:40 , Processed in 0.153761 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表