明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2425|回复: 4

[源码] 基于中点的文字反转v4源代码解析与测试 重写逻辑(支持块、嵌套块、外部参照、UCS)

[复制链接]
发表于 2014-1-11 16:50 | 显示全部楼层 |阅读模式
基于中点的文字反转扩展暨函数nentsel应用实例
重写逻辑,精简代码;扩展对嵌套块,Base支持。
原版本基于中点的文字反转v3源代码解析与测试(支持块、外部参照、UCS)http://bbs.mjtd.com/forum.php?mo ... amp;fromuid=7303580
思路:
函数nentsel,对于一般对象(not complex,that is, not a 3D polyline or block)选择,同entsel;否则能返回被选择的实体名,且带有一(MCS to WCS)转换矩阵与外部实体名(对于嵌套的情况)。具体应用详见代码。
基于上述函数,对于本文字反转的选择判断将不复存在。即对选择的文本执行RotateText即可,如果为块对象,则更新块对象。主函数ART(Advanced Totate Text)修改如下
  1. (defun C:ART () ;Advanced Rotate Text
  2. ;函数ART Advanced Rotate Text 文字绕自身中点反转,version 4.0 调整判断逻辑 。
  3. ;Desiged by 林霄云 2014年1月11日
  4. (princ "\n选择需要反转的文字:");提示不需要进入循环
  5.   (while(setq e  (nentsel)) ;Prompts the user to select an object (entity) by specifying a point, and provides access to the definition data contained within a complex object
  6.        (setq en (car e));The second element is a list containing the coordinates of the point used to pick the object.
  7.     (setq typ (cdr (assoc 0 (entget en))))
  8.        (cond
  9.        ((= (length e) 2) ;普通的entsel,判断是否为TEXT
  10.          (if (= typ "TEXT") ;如果判断是TEXT,则直接Rotate it。
  11.          (rotate-text en) );if TEXT
  12.        );cond 1
  13.       ((= (length e) 4) ;When the selected object is a component of a block reference other than an attribute, nentsel returns a list containing four elements.
  14.       (if (= typ "TEXT") ;如果判断是TEXT,则直接Rotate it。且更新块。
  15.       (progn     (rotate-text en)
  16.       ;更新块
  17.       (setq i -1)
  18.       (setq ss (ssget "X" (list (cons 2  (cdr (assoc 2 (entget (car(reverse(cadddr e)))))) ) ) )); The fourth element is a list containing the entity name of the block that contains the selected object.
  19. ;      If the selected object is in a nested block (a block within a block), the list also contains the entity names of all blocks in which the selected object is nested, starting with the innermost block and continuing outward until the name of the block that was inserted in the drawing is reported.
  20. ;      所以反转,取最外面的的块名。
  21.       (while (setq s1 (ssname ss (setq i (1+ i))))
  22.       (entupd s1))
  23.       );progn
  24.         );if TEXT
  25.       );cond2
  26.       );cond
  27.   (princ)
  28. );while
  29.   );defun
主函数中调用的RotateText函数详见前述版本,可见原版本的RotateText具有强通用性。
结果:
如测试截图所示,本文完美支持文字(基本功能),块,外部参照,外部参照里的块,UCS等情况的反转。
结论:
nentsel充分的将原各版本的判断缩减了。充分利用开发语言提供的函数能有更大的通用性。
另本稍加修改扩展,可以将本代码用修改文字内容等操作。

本帖子中包含更多资源

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

x
"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2014-1-11 17:46 | 显示全部楼层
对于块属性,由于其整体性,所以没有反转需求(ATTDEF in block),但是单个属性(ATTDEF),可以支持反转。简单的,将如下代码里的判断做如下修改,原语句
  1. ((= (length e) 2) ;普通的entsel,判断是否为TEXT
  2.          (if (= typ "TEXT") ;如果判断是TEXT,则直接Rotate it。
复制代码
修改为:
  1. ((= (length e) 2) ;普通的entsel,判断是否为TEXT
  2.          (if (vl-position typ '("ATTDEF" "TEXT")) ;如果判断是TEXT,则直接Rotate it。
复制代码
本反转文字,到此,可以搞一个段落了。终结版,可用。
发表于 2019-4-5 00:02 来自手机 | 显示全部楼层
可以来个直接修改参照里面文字的工具吗
发表于 2021-3-8 08:39 | 显示全部楼层
终于找到这个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-7-27 15:09 , Processed in 0.170129 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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