AutoLISP指定图层更换内容
2011-03-28 23:57 精诚所至 金石为开 阅读(1903) 评论(0) 编辑 收藏 举报AutoLISP指定图层更换内容,代码如下。
(defun c:test()
(setq oldtxt (getstring t "\n输入旧字符串:"))
(setq newtxt (getstring t "\n输入新字符串:"))
(setq layn (strcase (getstring "\n输入图层:")))
(setq ss (ssget "X" (list '(0 . "TEXT") (cons 8 layn))))
(setq oldnum (strlen oldtxt))
(setq newnum (strlen newtxt))
(setq i 0)
(repeat (sslength ss)
(setq ssn (ssname ss i))
(setq ssdata (entget ssn))
(setq p 1)
(setq ent (assoc 1 ssdata))
(setq entxt (cdr ent))
(setq ennum (strlen entxt))
(setq aa "")
(while (<= p ennum)
(setq kk (substr entxt p oldnum))
(if (= kk oldtxt)
(progn
(setq kk newtxt)
(setq p (- (+ p oldnum) 1))
)
(setq kk (substr entxt p 1))
)
(setq aa (strcat aa kk))
(setq p (1+ p))
)
(setq aa (cons 1 aa))
(setq ssdata (subst aa ent ssdata))
(entmod ssdata)
(setq i (1+ i))
)
(prin1)
)
代码完。
只对单行文字有效。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)