明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3237|回复: 14

[源码] 提取标注尺寸进行替换

[复制链接]
发表于 2013-11-16 13:07 | 显示全部楼层 |阅读模式
本帖最后由 lostbalance 于 2013-11-16 13:52 编辑

编了一个提取标注的尺寸,并替换文本的程序,适用于线性、对齐、半径、直径、角度和弧长标注。
注:弧长标注老版本的cad,比如04版之类的,没这个功能。
  1. (defun C:DimReplace( / dim bl jd len diment dimss dimty )
  2.   (princ "\n选择标注: ")
  3.   (setq dim (ssget '((0 . "DIMENSION"))))
  4.   (setq bl (getreal "\n标注比例: <1>"))
  5.   (if (not bl) (setq bl 1))
  6.   (setq jd (getint "\n标注精度: <0>"))
  7.   (if (not jd) (setq jd 0))
  8.   (if dim
  9.     (progn
  10.       (repeat
  11.         (setq len (sslength dim))
  12.         (setq diment (entget (ssname dim (setq len (1- len)))))
  13.         (setq dimss (cdr (assoc 1 diment)))
  14.         (if (or (= dimss "") (= dimss "<>"))
  15.           (progn
  16.             (setq dimty (cdr (assoc 70 diment)))
  17.             (setq dimss (cdr (assoc 42 diment)))
  18.             (cond
  19.               (  (or (= dimty 32) (= dimty 160);线性
  20.                   (= dimty 33) (= dimty 161);对齐
  21.                   (= dimty 37) (= dimty 165);弧长
  22.                 )
  23.                 (setq dimss (rtos (* dimss bl) 2 jd))
  24.               )
  25.               ((or (= dimty 34) (= dimty 162));角度
  26.                 (setq dimss (strcat (rtos (WYB-rtod dimss) 2 jd) "%%D"))
  27.               )
  28.               ((or (= dimty 35) (= dimty 163));直径
  29.                 (setq dimss (strcat "%%C" (rtos (* dimss bl) 2 jd)))
  30.               )
  31.               ((or (= dimty 36) (= dimty 164));半径
  32.                 (setq dimss (strcat "R" (rtos (* dimss bl) 2 jd)))
  33.               )
  34.             )
  35.             (entmod (subst (cons 1 dimss) (assoc 1 diment) diment))
  36.           )
  37.         )
  38.       )
  39.     )
  40.   )
  41.   (princ "\n完成标注的文本替换")
  42.   (princ)
  43. )


  44. (defun WYB-rtod(r)
  45.   (/ (* r 180) pi)
  46. )
"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

 楼主| 发表于 2017-8-21 08:59 | 显示全部楼层
梦里水香 发表于 2017-8-18 16:56
标注前面有文本的话替换失败,有没有解决办法呢?

用(wcmatch dimss "*<>*)定位<>,暂存其他的文字,然后计算并替换<>为数值。
有兴趣的话,还可以试着扩充一下功能,对于原来就是文字+数值的,分离出文字,然后重新计算并替换数值。
发表于 2017-8-18 16:56 | 显示全部楼层
标注前面有文本的话替换失败,有没有解决办法呢?
发表于 2017-9-17 22:26 | 显示全部楼层
很好用,不过坐标能不能也加进去?
发表于 2013-11-17 10:55 | 显示全部楼层
东西太好了
发表于 2014-5-11 12:38 | 显示全部楼层
楼主英明啊
发表于 2014-11-8 17:19 来自手机 | 显示全部楼层
看不了东西啊
发表于 2015-1-15 23:50 | 显示全部楼层
支持,谢谢分享!
发表于 2015-1-16 07:45 | 显示全部楼层
太棒啦!!!!
发表于 2015-4-10 22:54 | 显示全部楼层
支持源码。
发表于 2015-5-13 17:59 | 显示全部楼层
这个源码不错,谢谢分享。
发表于 2016-2-18 11:11 | 显示全部楼层
看看如何,学习下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-5 15:57 , Processed in 0.441384 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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