各位好!
前几天看到一个帖子,需要将文本去掉空格,但显示位置不变,这种程序本人以前也研究过,因为文字占位的算法问题,总是不能如意,这次又看到这种帖子,仔细考虑了一下,决定借用ExpressTools的函数acet-tjust(修改文本对齐方式)来实现,于是有了下面一段程序。
好久不动Lisp了,命令多记不住了,所以一边翻书、一边构思、一边成文,多少有些凌乱,好在简单测试,目的可以达到。因为不是常用程序,也不准备再作完善了。
- (defun c:ttrim(/ ss i l0 en ne eg ng e0 e1 j)
- (command ".color" (getvar "cecolor"))
- (princ "\n选择需要去空格的文本: ")
- (setq ss(ssget '((0 . "TEXT") (1 . "* *"))))
- (if ss
- (progn
- (setq l0 (sslength ss)
- i -1
- )
- (acet-tjust ss "R")
- )
- )
- (repeat l0
- (setq i (1+ i)
- en (ssname ss i)
- eg (entget en)
- e1 (cdr (assoc 1 eg))
- )
- (if (wcmatch e1 " *")
- (progn
- (setq e1 (vl-string-left-trim " " e1)
- eg (subst (cons 1 e1) (assoc 1 eg) eg)
- )
- (entmod eg)
- )
- )
- (if (wcmatch e1 "* ")
- (progn
- (acet-tjust (ssadd en) "S")
- (setq eg (entget en)
- e1 (cdr (assoc 1 eg))
- e1 (vl-string-right-trim " " e1)
- eg (subst (cons 1 e1) (assoc 1 eg) eg)
- )
- (entmod eg)
- )
- (acet-tjust (ssadd en) "S")
- )
- (while (wcmatch e1 "* *")
- (setq eg (entget en)
- ng (entmake eg)
- ne (entlast)
- ng (entget ne)
- e0 (cdr (assoc 1 ng))
- e0 (substr e0 1 (setq j (vl-string-search " " e0)))
- ng (subst (cons 1 e0) (assoc 1 ng) ng)
- )
- (entmod ng)
- (acet-tjust (ssadd en) "R")
- (setq eg (entget en)
- e1 (cdr (assoc 1 eg))
- e1 (vl-string-left-trim " " (substr e1 (+ j 1)))
- eg (subst (cons 1 e1) (assoc 1 eg) eg)
- )
- (entmod eg)
- (setq eg (entget en)
- e1 (cdr (assoc 1 eg))
- )
- (acet-tjust (ssadd en) "S")
- )
- )
- (princ)
- )
|