基于中点的文字反转扩展暨函数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)修改如下- (defun C:ART () ;Advanced Rotate Text
- ;函数ART Advanced Rotate Text 文字绕自身中点反转,version 4.0 调整判断逻辑 。
- ;Desiged by 林霄云 2014年1月11日
- (princ "\n选择需要反转的文字:");提示不需要进入循环
- (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
- (setq en (car e));The second element is a list containing the coordinates of the point used to pick the object.
- (setq typ (cdr (assoc 0 (entget en))))
- (cond
- ((= (length e) 2) ;普通的entsel,判断是否为TEXT
- (if (= typ "TEXT") ;如果判断是TEXT,则直接Rotate it。
- (rotate-text en) );if TEXT
- );cond 1
- ((= (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.
- (if (= typ "TEXT") ;如果判断是TEXT,则直接Rotate it。且更新块。
- (progn (rotate-text en)
- ;更新块
- (setq i -1)
- (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.
- ; 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.
- ; 所以反转,取最外面的的块名。
- (while (setq s1 (ssname ss (setq i (1+ i))))
- (entupd s1))
- );progn
- );if TEXT
- );cond2
- );cond
- (princ)
- );while
- );defun
主函数中调用的RotateText函数详见前述版本,可见原版本的RotateText具有强通用性。
结果:
如测试截图所示,本文完美支持文字(基本功能),块,外部参照,外部参照里的块,UCS等情况的反转。
结论:
nentsel充分的将原各版本的判断缩减了。充分利用开发语言提供的函数能有更大的通用性。
另本稍加修改扩展,可以将本代码用修改文字内容等操作。
|