明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: langjs

[函数] 修改了下grread捕捉子函数应该能用了

    [复制链接]
发表于 2023-7-29 18:49:11 | 显示全部楼层
之前用过楼主的代码,特此感谢
发表于 2024-7-24 11:03:52 | 显示全部楼层
好像还是不能捕捉圆心和几何中心
发表于 2024-7-24 11:32:36 | 显示全部楼层
本帖最后由 gzcsun 于 2024-8-10 00:08 编辑
228378553 发表于 2024-7-24 11:03
好像还是不能捕捉圆心和几何中心

自己加上。圆心 ,几何中心,图元中心 都可以有。
我是不用几何中心的,图元中心用得多。

cad原捕捉限显示6个;而且面域不能显示几何中心。

所以圆心限显示4个,
图元中心显示2个,面域,块,多段线的都能显示,其它的要按一下按键才显示


本帖子中包含更多资源

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

x

点评

图元中心,创意无限  发表于 2024-7-24 14:07
回复 支持 1 反对 0

使用道具 举报

发表于 2024-7-24 13:44:17 | 显示全部楼层
gzcsun 发表于 2024-7-24 11:32
自己加上。圆心 ,几何中心,图元中心 都可以有。
我是不用几何中心的,图元中心用得多。

不知道怎么加
发表于 2024-8-9 16:43:03 | 显示全部楼层
gzcsun 发表于 2024-7-24 11:32
自己加上。圆心 ,几何中心,图元中心 都可以有。
我是不用几何中心的,图元中心用得多。

我不会加  想求代码,你发个帖子 我给明经币
发表于 2025-2-14 14:35:16 | 显示全部楼层
正是我想要 的..感谢楼主..............
回复 支持 反对

使用道具 举报

发表于 2025-2-15 10:30:41 | 显示全部楼层

很好很强大的功能,谢谢分享
回复 支持 反对

使用道具 举报

发表于 2025-5-24 21:56:37 | 显示全部楼层
本帖最后由 逗亦斗霸 于 2025-5-25 15:47 编辑
llsheng_73 发表于 2020-8-11 10:33
建议 (osnap pt "_END,_CEN,_NOD,_QUA,_INS,_TAN,_EXT")根据当前的捕捉设置来
我把G版那个按我的习惯修改 ...

请问一下,这段代码还有其他的范例吗?我尝试使用这段加到我动态引线捕捉里去只显示方框,靠近中点时不能正常显示三角形,在另一个拉线标注里倒是可以在靠近中点时正常显示三角形,谢谢~
  1.   (defun dectobin(n m / c f);;十进制转二进制
  2.   (setq f(if(< n 0)1 0)n(abs n))
  3.   (while(>(setq c(cons(rem n 2)c)n(/ n 2))0))
  4.   (while(<(length c)(1- m))(setq c(cons 0 c)))
  5.   (cons f c))
  6. (DEFUN DrawVecs(pt Vecs Size Color / xdir);;;G版函数绘制矢量
  7.   (setq xdir(getvar'ucsxdir)
  8.   Vecs(mapcar'(lambda(x)(mapcar'(lambda(a)(mapcar'+ pt(mapcar'*(setq a(trans a 0 xdir)a(list(caddr a)(car a)))(List size size))))x))Vecs))
  9.   (GRVECS(APPLY 'APPEND(MAPCAR 'CONS(MAPCAR(FUNCTION (LAMBDA (x)Color))Vecs)Vecs))))
  10. (defun myosnap(pt / xpt mode osmod osmode Draftobj Size);;;修改G版函数带捕捉grread
  11. (redraw)
  12.   (if(setq Draftobj(VLA-GET-DRAFTING(VLA-GET-PREFERENCES(VLAX-GET-ACAD-OBJECT)))
  13.      osmod'("_END," "_MID," "_CEN," "_NOD," "_QUA," "_INT," "_INS," "_PER," "_TAN," "_NEA," "_NON," "_APP," "_EXT," "_PAR")
  14.      osmode(reverse(DECTOBIN (getvar'osmode) 1))
  15.      size(*(/(getvar "viewsize")(cadr(getvar "screensize")))(VLA-GET-AUTOSNAPMARKERSIZE Draftobj))
  16.      xpt(osnap pt(apply'strcat(mapcar'(lambda(x y)(if(zerop x)""y))osmode osmod)))
  17.      mode(CDR(ASSOC
  18.       (if xpt(vl-some'(lambda(x)(if(equal xpt(cdr x)1e-8)(car x)))
  19.              (vl-remove'nil(mapcar'(lambda(x y / xpt)(if(zerop x)nil(if(setq xpt(osnap pt y))(cons y xpt))))osmode osmod)))"_NON,")
  20.       '(("_END,"((-1 1)(-1 -1))((-1 -1)(1 -1))((1 -1) (1 1))((1 1) (-1 1)))
  21.         ("_MID,"((0 1.414) (-1.225 -0.707)) ((-1.225 -0.707)(1.225 -0.707))((1.225 -0.707) (0 1.414)))
  22.         ("_CEN,"((0 1) (-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0) (-0.707 -0.707))((-0.707 -0.707)(0 -1))
  23.          ((0 -1)(0.707 -0.707))((0.707 -0.707)(1 0)) ((1 0) (0.707 0.707))((0.707 0.707) (0 1)))
  24.         ("_NOD,"((0 1) (-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0)(-0.707 -0.707))((-0.707 -0.707)(0 -1))((0 -1)(0.707 -0.707))
  25.          ((0.707 -0.707)(1 0))((1 0)(0.707 0.707))((0.707 0.707)(0 1))((-1 1)(1 -1))((-1 -1)(1 1)))
  26.         ("_QUA,"((0 1.414)(-1.414 0))((-1.414 0)(0 -1.414))((0 -1.414)(1.414 0))((1.414 0)(0 1.414)))
  27.         ("_INT,"((-1 1)(1 -1))((-1 -1)(1 1))((1 0.859)(-0.859 -1))((-1 0.859)(0.859 -1))((0.859 1)(-1 -0.859))((-0.859 1)(1 -0.859)))
  28.         ("_INS,"((-1 1)(-1 -0.1))((-1 -0.1)(0 -0.1))((0 -0.1)(0 -1.0))((0 -1.0)(1 -1))
  29.          ((1 -1)(1 0.1))((1 0.1)(0 0.1))((0 0.1) (0 1.0))((0 1.0)(-1 1)))
  30.         ("_PER,"((-1 1)(-1 -1))((-1 -1)(1 -1))((0 -1)(0 0))((0 0)(-1 0)))
  31.         ("_TAN,"((0 1)(-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0)(-0.707 -0.707))((-0.707 -0.707)(0 -1))
  32.          ((0 -1)(0.707 -0.707))((0.707 -0.707)(1 0))((1 0)(0.707 0.707))((0.707 0.707)(0 1))((1 1)(-1 1)))
  33.         ("_NEA,"((-1 1)(1 -1))((1 -1)(-1 -1))((-1 -1)(1 1))((1 1)(-1 1)))
  34.         ("_NON,")
  35.         ("_APP,"((-1 1)(-1 -1))((-1 -1)(1 -1))((1 -1)(1 1))((1 1)(-1 1))((-1 1)(1 -1))((-1 -1)(1 1)))
  36.         ("_EXT,"((0.1 0)(0.13 0))((0.2 0)(0.23 0))((0.3 0)(0.33 0)))
  37.         ("_PAR"((0 1)(-1 -1))((1 1)(0 -1)))))))
  38.     (DrawVecs(setq xpt(if xpt xpt pt))mode size(VLA-GET-AUTOSNAPMARKERCOLOR Draftobj)))
  39.   (if xpt xpt pt))
  40. (defun c:tvvt(/ e xpt) ;;选择一个圆进行移动
  41.   (while(setq e(ssget":E:S"'((0 . "circle"))))
  42.     (setq e(entget(ssname e 0)))
  43.     (while(/=(car(setq xpt(grread t 15 0)))3)(redraw)
  44.       (if(=(car xpt)5)(entmod(append e(list(cons 10(myosnap(cadr xpt)))))))
  45.       ))
  46.   )

  47. (defun bz (/ *error* name1 name2 name3)
  48.     (defun *error* (msg)    ;将描述错误的字符串存入变量msg
  49.   (entdel name1)
  50.   (entdel name2)
  51.   (if name3
  52.       (entdel name3)
  53.   )
  54.   (princ "错误: ")
  55.   (princ msg)
  56.     )          ;打印错误信息
  57.    
  58.     (setq ty (getvar "TEXTSTYLE"))
  59.     (setq ht (atof txtht))
  60.     (if (= ht 0)
  61.   (progn
  62.   (prompt "字高为0!")
  63.   (terpri)
  64.   );progn
  65.   );if
  66.     (setq Scale (/ ht 2.5));
  67.     (setq kd1 (caadr (textbox (list '(0 . "text")
  68.             (cons 1 txt1)
  69.             (cons 40 ht)
  70.             (cons 41 1)
  71.             (cons 7 ty)
  72.             (cons 62 7)
  73.             )
  74.          )
  75.         )
  76.     )
  77.           ;字高ht,字宽高比1,可以自己设置,字体为当前字体
  78.     (setq kd2 (caadr (textbox (list '(0 . "text")
  79.             (cons 1 txt2)
  80.             (cons 40 ht)
  81.             (cons 41 1)
  82.             (cons 7 ty)
  83.             (cons 62 7)
  84.             )
  85.          )
  86.         )
  87.     )
  88.           ;字高ht,字宽高比1,可以自己设置,字体为当前字体
  89.     (setq kd (max kd1 kd2)
  90.     kd (+ kd (* 0.50 Scale))
  91.     )
  92.     (setq p (getpoint "\n输入基点:"))
  93.     (setq pd t)
  94.     (while pd
  95.   (setq gr   (grread t 4 1)
  96.         mode (car gr)
  97.         pt   (myosnap (cadr gr))
  98.   )
  99.   (if (= kd3 0)
  100.       (setq kd kd1)
  101.   )
  102.   (if (and (listp pt) (>= (car pt) (car p)))
  103.       (progn
  104.     (setq p0 (polar pt 0 kd))
  105.     (setq p1 (polar pt 0 (/ (- kd kd1) 2))
  106.           p1 (polar p1 (angtof "90") (* 0.70 Scale))
  107.     )
  108.     (setq p2 (polar pt 0 (/ (- kd kd2) 2))
  109.           p2 (polar p2 (angtof "270") (* 3.20 Scale))
  110.     )
  111.       )
  112.   )
  113.   (if (and (listp pt) (< (car pt) (car p)))
  114.       (progn
  115.     (setq p0 (polar pt pi kd))
  116.     (setq p1 (polar p0 0 (/ (- kd kd1) 2))
  117.           p1 (polar p1 (angtof "90") (* 0.70 Scale))
  118.     )
  119.     (setq p2 (polar p0 0 (/ (- kd kd2) 2))
  120.           p2 (polar p2 (angtof "270") (* 3.20 Scale))
  121.     )
  122.       )
  123.   )
  124.   (if (= mode 5)
  125.       (progn
  126.     (if name1
  127.         (entdel name1)
  128.     )
  129.     (entmake (list '(0 . "LWPOLYLINE")
  130.              '(100 . "AcDbEntity")
  131.              '(100 . "AcDbPolyline")
  132.              '(90 . 3)
  133.              (cons 10 p)
  134.              (cons 10 pt)
  135.              (cons 10 p0)
  136.              (cons 62 3)
  137.        )
  138.     )
  139.     (setq name1 (entlast))
  140.     (if name2
  141.         (entdel name2)
  142.     )
  143.     (entmake (list '(0 . "text")
  144.              (cons 1 txt1)
  145.              (cons 40 ht)
  146.              (cons 41 1)
  147.              (cons 10 p1)
  148.              (cons 7 ty)(cons 62 7)
  149.        )
  150.     )
  151.           ;字高ht,字宽高比1,可以自己设置,字体为当前字体
  152.     (setq name2 (entlast))
  153.     (if name3
  154.         (entdel name3)
  155.     )
  156.     (if (= kd3 1)
  157.         (entmake (list '(0 . "text")
  158.            (cons 1 txt2)
  159.            (cons 40 ht)
  160.            (cons 41 1)
  161.            (cons 10 p2)
  162.            (cons 7 ty)(cons 62 7)
  163.            )
  164.         )
  165.     )
  166.           ;字高ht,字宽高比1,可以自己设置,字体为当前字体
  167.     (if (= kd3 1)
  168.         (setq name3 (entlast))
  169.     )
  170.       )
  171.     (redraw)
  172.   )
  173.   (if (= mode 3)
  174.       (setq pd nil)
  175.   )
  176.   (if (or (= mode 2) (= mode 25))
  177.       (progn (setq pd nil)
  178.        (entdel name1)
  179.        (entdel name2)
  180.        (if name3
  181.            (entdel name3)
  182.        )
  183.       )
  184.   )
  185.     )
  186.     (princ)
  187. )

  188. (defun getdata ()
  189.     (setq txt1 (get_tile "a1"))
  190.     (setq txt2 (get_tile "a2"))
  191.     (if  (= (get_tile "a3") "0")
  192.   (setq kd3 0)
  193.   (setq kd3 1)
  194.     )
  195.     (setq txtht(get_tile "a4"))
  196. )

  197. (defun c:bz ()
  198.           ;(步骤1)建立临时对话框
  199.     (setq tempname (vl-filename-mktemp "temp.dcl")
  200.     filen     (open tempname "w")
  201.     )
  202.     (foreach stream
  203.        '("bz:dialog{"
  204.          "\n  label = "
  205.          动态引线标注
  206.          ";"
  207.          "\n  :edit_box {key = "a1"; label = "线上文字:"; width = 40 ;}"
  208.          "\n  :toggle {key = "a3"; label = "增加线下文字"; value = "
  209.          0
  210.          ";}"
  211.          "\n  :edit_box {key = "a2"; label = "线下文字:"; width = 40; is_enabled = false;}"
  212.          "\n  :edit_box {key = "a4"; label = "文字高度:"; width = 20; }"
  213.          "\n  ok_cancel;}"
  214.         )
  215.   (princ stream filen)
  216.     )
  217.     (close filen)
  218.     (setq dclname tempname)
  219.           ;(步骤2)加载并显示对话框
  220.     (setq dcl_re (load_dialog dclname))
  221.     (if  (not (new_dialog "bz" dcl_re))
  222.   (exit)
  223.     )
  224.           ;(步骤3)定义对话框控件(运用set_tile、action_tile、mode_tile、get_tile等函数)
  225.     (if  txt1
  226.   (set_tile "a1" txt1)
  227.   (set_tile "a1" "动态标注")
  228.     )
  229.     (if  txt2
  230.   (set_tile "a2" txt2)
  231.   (set_tile "a2" "动态标注")
  232.     )
  233.     (if  kd3
  234.   (set_tile "a3" (rtos kd3))
  235.     )          ;注意set_tile函数中赋值均为字符串(带双引号),就连关键词也要加上双引号。
  236.     (if  (= kd3 0)
  237.   (mode_tile "a2" 1)
  238.     )
  239.     (if  (= kd3 1)
  240.   (mode_tile "a2" 0)
  241.     )
  242.     (if  txtht
  243.   (set_tile "a4" txtht)
  244.   (set_tile "a4" "150")
  245.     )
  246.     (action_tile
  247.   "a3"
  248.   "(if (= (get_tile "a3") "0") (mode_tile "a2" 1) (mode_tile "a2" 0))"
  249.     )          ;点击时才起作用
  250.     (action_tile "accept" "(getdata)(done_dialog 1)")
  251.     (action_tile "cancel" "(done_dialog)")
  252.           ;(步骤4)激活并卸载对话框,并进行对话框隐藏后的操作。
  253.     (setq std (start_dialog))
  254.     (unload_dialog dcl_re)
  255.     (vl-file-delete dclname)
  256.     (if  (= std 1)
  257.   (bz)
  258.     )
  259.     (princ)
  260. )


回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
逗亦斗霸 发表于 2025-5-24 21:56
请问一下,这段代码还有其他的范例吗?我尝试使用这段加到我动态引线捕捉里去只显示方框,靠近中点时不能 ...

("_MID,"((0 1.414) (-1.225 -0.707)) ((-1.225 -0.707)(1.225 -0.707))((1.225 -0.707) (0 1.414)))
应该是要修改这个后边的坐标表,空了收拾它一下
回复 支持 反对

使用道具 举报

发表于 6 天前 | 显示全部楼层
llsheng_73 发表于 2025-5-26 11:50
("_MID,"((0 1.414) (-1.225 -0.707)) ((-1.225 -0.707)(1.225 -0.707))((1.225 -0.707) (0 1.414)))
应 ...

好的,那就静候大佬的更新,谢谢啦~
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-1 16:22 , Processed in 0.239272 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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