明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 200|回复: 2

[源码] 圆周上的文字顺(逆)时针编号

[复制链接]
发表于 2024-4-9 10:42 | 显示全部楼层 |阅读模式
BF-pickset->list:AutoLispBaseFunctionLibraryAutoCAD的AutoLisp/Vlisp的基础通用函数库函数;
InspireFunction: 跃动方程(英文名为:Inspire Function)是一个编程爱好者成立的非营利性组织。 (gitee.com)
Cad二次开发类库ifoxCAD的维护大佬:山人等大佬维护整理的基础通用函数库
  1. ;;(CNUM)圆周上的文字顺(逆)时针编号 by 702099480@qq.com 2024.4.9
  2. (defun C:CNUM(/ ang bf-pickset->list dxf edata ent lst lst1 lst2 num pt ss sslst timerun)
  3.   (defun BF-pickset->list (SS)
  4.     (vl-remove-if-not '(lambda (arg) (equal (type arg) 'ENAME)) (mapcar 'cadr (ssnamex SS)))
  5.   )
  6.   (defun dxf (code ent) (cdr (assoc code (entget ent))))
  7.   (while (setq ss (ssget '((0 . "*TEXT"))))
  8.     (setq num (getint "\n请输入起始编号,默认:<1>"))
  9.     (if (or (= num "") (= num nil)) (setq num 1))
  10.     (setq ang (getangle "\n请输入起始弧度值[0-2π],默认:<0>"))
  11.     (if ang () (setq ang 0))
  12.     (initget "s S n N")
  13.     (setq timerun (getkword "\n[顺时针(S)/逆时针(N)],默认逆时针:<N>"))
  14.     (if timerun (setq timerun (strcase timerun)) (setq timerun "N"))
  15.     (if (setq pt (getpoint "\n指定中心点:"))
  16.       (progn
  17.         (setq sslst (BF-pickset->list ss))
  18.         (cond
  19.           ((= ang 0)
  20.             (setq lst (vl-sort sslst '(lambda(x y)(< (angle pt (dxf 10 x)) (angle pt (dxf 10 y))))))
  21.             (if (equal timerun "S") (setq lst (reverse lst)))
  22.           )
  23.           (t
  24.             (setq lst1 (vl-remove-if-not '(lambda(x) (and (>= (angle pt (dxf  10 x)) ang) (< (angle pt (dxf 10 x)) (* 2 pi)))) sslst))
  25.             (setq lst1 (vl-sort lst1 '(lambda(x y)(< (angle pt (dxf 10 x)) (angle pt (dxf 10 y))))))
  26.             
  27.             (setq lst2 (vl-remove-if-not '(lambda(x) (and (>= (angle pt (dxf 10 x)) 0) (< (angle pt (dxf 10 x)) ang))) sslst))
  28.             (setq lst2 (vl-sort lst2 '(lambda(x y)(< (angle pt (dxf 10 x)) (angle pt (dxf 10 y))))))
  29.             
  30.             (if (equal timerun "S")
  31.               (setq lst (append (reverse lst2) (reverse lst1)))
  32.               (setq lst (append lst1 lst2))
  33.             )
  34.           )
  35.         )
  36.         (while (setq ent (car lst))
  37.           (setq edata (entget ent))
  38.           (setq edata (subst (cons 1 (rtos num)) (assoc 1 edata) edata))
  39.           (entmod edata)
  40.           (setq lst (cdr lst) num (1+ num))
  41.         )
  42.       )
  43.     )
  44.   )
  45.   (prin1)
  46. )


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

代码还可以进一步优化  发表于 2024-4-10 20:00
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2024-4-9 18:26 | 显示全部楼层
感谢分享,围绕圆的数字,搭配环形阵列,刚好能够应用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-30 20:08 , Processed in 0.545929 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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