明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 896|回复: 9

[提问] 下划线加反应器自动更新(功能实现但是有点bug)

[复制链接]
发表于 2023-2-5 19:28 | 显示全部楼层 |阅读模式


下划线的代码是@zj20190405http://bbs.mjtd.com/forum.php?mo ... =%CF%C2%BB%AE%CF%DF
帖子里发布的,不知道是不是他的原创,取用了就感谢一下!

这两天刚学到反应器,就想着能不能加一个,然后就有了下面这个代码


刚学autolisp不久,写的乱七八糟的,好歹功能是实现了,但是有以下问题
1:源代码是可以批量下划线的,我的反应器没有写循环,所有只能实现最后一下文字划线自动更新
2:没有写单行文字的,只写了多行文字的,自定义变量太多了,脑子昏,以后有机会完善吧
3:一个神奇的bug:有时候会自动更新,有时候最后还需要编辑一次文本,或者移动它才会更新图元,我明明加了(entmod)啊!

本帖子中包含更多资源

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

x

评分

参与人数 1明经币 +1 收起 理由
cghdy + 1

查看全部评分

 楼主| 发表于 2023-2-5 19:29 | 显示全部楼层
  1. ;下划线程序
  2. (vl-load-com)
  3. (defun c:xxx ( / i n pt_bc pt_bl pt_br pt_mc pt_tc pttl pttr roundspace ss1 tbox txtentdata txtentname txtenttype xangle xheight xwidth)
  4.   (setq ss1 (ssget '((0 . "*TEXT"))))
  5.   (setq text (entlast))
  6.   (if (null ss1)
  7.     (progn
  8.       (princ "\n没有文本实体被选择!")
  9.       (exit)
  10.     )                                        ; end progn
  11.   )                                        ; end if
  12.   (setq n (sslength ss1))
  13.   (if (not (= nil n))                        ; no select objects
  14.     (progn
  15.       (setq i 0)
  16.       (while (< i n)
  17.         (setq txtentname (ssname ss1 i))
  18.         (setq txtentdata (entget txtentname))
  19.         (setq i (+ i 1))
  20.         (setq txtenttype (cdr (assoc 0 txtentdata)))
  21.                                         ; get entity's name:
  22.                                         ; "text" or "mtext"
  23.         (if (= txtenttype "TEXT")        ; this object is simple line text
  24.           (progn
  25.             (vl-cmdf "ucs" "Object" txtentname)
  26.                                         ; 定义用户坐标系到文本的方?
  27.             (setq tbox        (textbox (list (car txtentdata)))
  28.                                         ; must change to a list
  29.                   pt_bl        (car tbox)        ; left bottom point coords
  30.                   pttr        (cadr tbox)        ; right top point coords
  31.                   pttl        (list (car pt_bl) (cadr pttr))
  32.                   pt_br        (list (car pttr) (cadr pt_bl))
  33.             )                                ; end setq
  34.             (setq roundspace (* 0.2 (distance pt_bl pttl)))
  35.             (setq pt_bl (polar pt_bl pi (* roundspace 2)))
  36.             (setq pt_bl (polar pt_bl (* pi 1.5) roundspace))
  37.             (setq pt_br (polar pt_br 0.0 (* roundspace 2)))
  38.             (setq pt_br (polar pt_br (* pi 1.5) roundspace)) ;
  39.             (vl-cmdf "pline"
  40.                      pt_bl
  41.                      "w"
  42.                      (* roundspace 0.25)
  43.                      ""
  44.                      pt_br
  45.                      ""
  46.             )
  47.             (vl-cmdf "CHPROP" (entlast) "" "C" "BYBlock" "")
  48.             (vl-cmdf "pline"
  49.                      (polar pt_bl (* pi 1.5) (* roundspace 0.6))
  50.                      "w"
  51.                      0
  52.                      ""
  53.                      (polar pt_br (* pi 1.5) (* roundspace 0.6))
  54.                      ""
  55.             )
  56.             (vl-cmdf "CHPROP" (entlast) "" "C" "BYBlock" "")
  57.             (vl-cmdf "ucs" "p")
  58.           )                                ; end progn
  59.           (progn
  60.             (vl-cmdf "_.JustifyText" txtentname "" "TL")
  61.                                         ; 处理为对对齐模式.
  62.             (setq txtentdata (entget txtentname))
  63.             (setq pttl          (cdr (assoc 10 txtentdata));文字第一对其点y坐标
  64.                   xwidth  (cdr (assoc 42 txtentdata));文字水平宽度
  65.                   xheight (cdr (assoc 43 txtentdata));文字水平高度
  66.                   xangle  (cdr (assoc 50 txtentdata));文字旋转角度
  67.                   pt_tc          (polar pttl xangle (* xwidth 0.5))
  68.                   pttr          (polar pttl xangle xwidth)
  69.                   pt_bl          (polar pttl (- xangle (/ pi 2.0)) xheight)
  70.                   pt_bc          (polar pt_bl xangle (* xwidth 0.5))
  71.                   pt_br          (polar pt_bl xangle xwidth)
  72.                   pt_mc          (polar pt_bl (angle pt_bl pttr) (/ (distance pt_bl pttr ) 2.0 ))                ; end polar
  73.             )
  74.       ; end setq
  75.             (setq roundspace (* 0.2 (distance pt_bl pttl)));字的基准点到第一条直线的垂直距离
  76.             (setq xangle (cdr (assoc 50 txtentdata)))
  77.             (setq pt_bl (polar pt_bl xangle (- roundspace)))
  78.             (setq
  79.               pt_bl (polar pt_bl (+ xangle (/ pi 2.0)) (- roundspace))
  80.             );第一条直线的左端点
  81.             (setq pt_br (polar pt_br xangle roundspace))
  82.             (setq pt_br (polar pt_br (+ xangle (/ pi 2.0)) (- roundspace)));第一条直线的右端点
  83.             (setq pttl (polar pttl xangle (- roundspace)))
  84.             (setq pttl (polar pttl (+ xangle (/ pi 2.0)) roundspace))
  85.             (setq pttr (polar pttr xangle roundspace))
  86.             (setq pttr (polar pttr (+ xangle (/ pi 2.0)) roundspace)) ;
  87.             (vl-cmdf "pline" pt_bl "w" (* roundspace 0.25) "" pt_br "");画第一条直线
  88.       (setq eh1(cdr(assoc 5(entget(entlast)))));第一条直线的句柄
  89.       (setq pt_bl1 (polar pt_bl (* pi 1.5) (* roundspace 0.6)))
  90.       (setq pt_br1 (polar pt_br (* pi 1.5) (* roundspace 0.6)))
  91.             (vl-cmdf "CHPROP" (entlast) "" "C" "BYBlock" "")
  92.       (vl-cmdf "pline" pt_bl1  "w" 0 "" pt_br1 "");画第二条直线
  93.       (setq eh2(cdr(assoc 5(entget(entlast)))));第二条直线的句柄
  94.             (vl-cmdf "CHPROP" (entlast) "" "C" "BYBlock" "")
  95.                                         ; end command
  96.           )                                ; end progn
  97.         )                                ; end if
  98.       )                                        ; end while
  99.     )                                        ; end progn
  100.   ); end if
  101.   (vl-cmdf "ucs" "W")
  102.     (setq l1-l2(list eh1 eh2));两条直线的句柄表
  103.   (setq rlt(list(vlax-ename->vla-object text)));字的图元名转换为VLA对象
  104.   (setq vrl(vlr-pers(vlr-object-reactor rlt l1-l2 '((:vlr-modified . c-2l)))));反应器链接到圆上,两条直线的句柄表为关联数据,当发生修改该圆
  105.   (princ)
  106. )

  107. ;反应器
  108. ;         
  109. (defun c-2l(notifier-object reactor-object parameter-list /)
  110.   (setq text(vlax-vla-object->ename notifier-object);VLA对象转换
  111.     ec_l (entget text);新字的图元表
  112.       pttl_1          (cdr (assoc 10 ec_l));文字第一对其点y坐标
  113.                   xwidth_1  (cdr (assoc 42 ec_l));文字水平宽度
  114.                   xheight_1 (cdr (assoc 43 ec_l));文字水平高度
  115.                   xangle_1  (cdr (assoc 50 ec_l));文字旋转角度
  116.                   pt_tc_1          (polar pttl_1 xangle_1 (* xwidth_1 0.5))
  117.                   pttr_1          (polar pttl_1 xangle_1 xwidth_1)
  118.                   pt_bl_1          (polar pttl_1 (- xangle_1 (/ pi 2.0)) xheight_1)
  119.                   pt_bc_1          (polar pt_bl_1 xangle_1 (* xwidth_1 0.5))
  120.                   pt_br_1          (polar pt_bl_1 xangle_1 xwidth_1)
  121.                   pt_mc_1          (polar pt_bl_1 (angle pt_bl_1 pttr_1) (/ (distance pt_bl_1 pttr_1 ) 2.0 ))                ; end polar
  122.             )
  123.   (setq el1(handent(car(vlr-data reactor-object))));第一条直线的图元名
  124.   (setq el2(handent(cadr(vlr-data reactor-object))));第二条直线的图元名

  125.     (setq roundspace_1 (* 0.2 (distance pt_bl_1 pttl_1)));字的基准点到第一条直线的垂直距离
  126.             
  127.   
  128.   (setq pt_bl_1 (polar pt_bl_1 xangle_1 (- roundspace_1)))
  129.   (setq pt_bl_1 (polar pt_bl_1 (+ xangle_1 (/ pi 2.0)) (- roundspace_1)));更改第一条直线的左端点
  130.         (setq pt_br_1 (polar pt_br_1 xangle_1 roundspace_1))
  131.         (setq pt_br_1 (polar pt_br_1 (+ xangle_1 (/ pi 2.0)) (- roundspace_1)));第一条直线的右端点
  132. (setq ell_1(entget el1));第一条直线的图元表
  133. (setq ell_1(subst(vl-list* 10 pt_bl_1)(assoc 10 ell_1)ell_1));直线的新端点
  134. (setq ell_1(reverse ell_1))
  135. (setq ell_1(subst(vl-list* 10 pt_br_1)(assoc 10 ell_1)ell_1))
  136. (setq ell_1(reverse ell_1))
  137.   (entmod ell_1);更新第一条直线
  138.   (setq ell_2(entget el2));第二条直线的图元表
  139.     (setq pt_bl1_1 (polar pt_bl_1 (* pi 1.5) (* roundspace_1 0.6)))
  140.   (setq pt_br1_1 (polar pt_br_1 (* pi 1.5) (* roundspace_1 0.6)))
  141. (setq ell_2(subst(vl-list* 10 pt_bl1_1)(assoc 10 ell_2)ell_2));直线的新端点替换直线
  142. (setq ell_2(reverse ell_2))
  143. (setq ell_2(subst(vl-list* 10 pt_br1_1)(assoc 10 ell_2)ell_2))
  144. (setq ell_2(reverse ell_2))
  145. (entmod ell_2);更新第二条直线
  146. )

发表于 2023-2-5 19:39 来自手机 | 显示全部楼层
谢谢分享,这个功能好
发表于 2023-2-5 19:43 | 显示全部楼层
实用的功能,多谢分享
发表于 2023-2-5 21:51 | 显示全部楼层
谢谢楼主分享
发表于 2023-2-5 21:58 | 显示全部楼层
这个不错,不过还有个问题,整体移动会有问题
发表于 2023-2-5 22:09 | 显示全部楼层
这个也是整体移动有问题,但是是间歇的,第一次移动有问题,第二次就好了,第三次有问题,第四次又好了。。http://bbs.mjtd.com/forum.php?mo ... =%B7%B4%D3%A6%C6%F7
发表于 2023-2-6 13:11 | 显示全部楼层
谢谢楼主分享
发表于 2023-2-6 13:52 来自手机 | 显示全部楼层
谢谢高人分享
发表于 2023-10-26 16:58 | 显示全部楼层
http://bbs.mjtd.com/forum.php?mo ... amp;_dsign=64771105
求助反应器entmod无法更新图元(已解决)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-19 19:26 , Processed in 0.755282 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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