[求助](已完成)求lsp程序,选择含分号的字符串,将分号“;”前的字符改成用户输入的
本帖最后由 作者 于 2008-4-23 19:06:07 编辑 <br /><br /> [求助](已完成)求lsp程序,选择含分号的字符串,将分号“;”前的字符改成用户输入的字符求lsp程序,选择含分号的字符串,将分号“;”前的字符改成用户输入的字符(要求先输入字符,后选择)。<br/>如:2D25;2D20 用户输入2A18,则变成2A18;2D20<br/>如:2D20/2D18;2D25用户输入2D25/2D20,则变成2D25/2D20;2D25;替换分号前字符 明经 ZZXXQQ 2008.4.16
(defun c:tt ()
(if (setq news (getstring "\nEnter New string 输入新字串 :"))
(if (setq ss (ssget '((0 . "TEXT") (1 . "*;*")))) (progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i)
ent (entget(ssname ss i))
txt (cdr(assoc 1 ent))
j 1
sl (strlen txt))
(while (and (< j sl) (/= (setq s1 (substr txt j 1)) ";")) (setq j (1+ j)))
(setq ent (subst (cons 1 (strcat news (substr txt j))) (assoc 1 ent) ent))
(entmod ent)
)
))
)
(princ)
)
<p>CAD2004 测试可用,谢谢<font face="Verdana" color="#da2549"><strong>ZZXXQQ</strong><font color="#000000">版主,</font></font></p><p><font face="Verdana">呵呵,有时还需要修改分号后边的字符,可不可以写一个修改分号后边字符的程序呢?已知条件与上面的一样,只是想替换掉分号后边的字符。</font></p><p><font face="Verdana">再次感谢。</font></p>
;替换分号后字符 明经 ZZXXQQ 2008.4.16
(defun c:tt ()
(if (setq news (getstring "\nEnter New string 输入新字串 :"))
(if (setq ss (ssget '((0 . "TEXT") (1 . "*;*")))) (progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i)
ent (entget(ssname ss i))
txt (cdr(assoc 1 ent))
j 1
sl (strlen txt))
(while (and (< j sl) (/= (setq s1 (substr txt j 1)) ";")) (setq j (1+ j)))
(setq ent (subst (cons 1 (strcat (substr txt 1 j) news)) (assoc 1 ent) ent))
(entmod ent)
)
))
)
(princ)
)
本帖最后由 作者 于 2008-4-20 14:15:22 编辑 <br /><br /> <p>4楼程序cad2004测试可用,谢谢<strong><font face="Verdana" color="#da2549">ZZXXQQ版主的关注。</font></strong></p><p><strong><font face="Verdana" color="#da2549"></font></strong></p><p><strong><font face="Verdana" color="#da2549">可以给“输入新字符串”加个“2]25”的默认值吗?还有,键盘输入的所有点号“.”在cad中都变成“]”号。</font></strong></p><p><font face="Verdana" color="#da2549"><font color="#000000">如:2D25;2D20 用户输入2.18,则变成2]18;2D20<br/>如:2D20/2D18;2D25用户输入2.25/2.20,则变成2]25/2]20;2D25</font></font></p><p><font face="Verdana"></font></p><p><font face="Verdana">谢谢。</font></p> 本帖最后由 作者 于 2008-4-20 14:55:06 编辑
子程序见晓东。
;替换分号后字符 明经 ZZXXQQ 2008.4.20
(defun c:tt ()
(if (setq news (getstring "\nEnter New string 输入新字串 <2]25> :")) (progn
(setq news (if (= (strlen news) 0) "2]25" news))
(while (wcmatch news "*.*") (setq news (chchar news "." "]")))
(if (setq ss (ssget '((0 . "TEXT") (1 . "*;*")))) (progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i)
ent (entget(ssname ss i))
txt (cdr(assoc 1 ent))
j (strlen txt)
sl j)
(while (and (> j 1) (/= (setq s1 (substr txt j 1)) ";")) (setq j (1- j)))
(setq ent (subst (cons 1 (strcat (substr txt 1 j) news)) (assoc 1 ent) ent))
(entmod ent)
)
))
))
(princ)
)
<p></p><p>配合晓东<strong><font face="宋体">zxq0220的子程序,下面程序cad2004测试无反应,不知何故,不支持“]”号。</font></strong></p><p>;替换分号后字符 明经 ZZXXQQ 2008.4.20<br/>(defun c:tt ()<br/> (if (setq news (getstring "\nEnter New string 输入新字串 <2]25> :")) (progn<br/> (setq news (if (= (strlen news) 0) "2]25" news))<br/> (while (wcmatch news "*.*") (setq news (chchar news "." "]")))<br/> (if (setq ss (ssget '((0 . "TEXT") (1 . "*;*")))) (progn<br/> (setq i -1)<br/> (repeat (sslength ss)<br/> (setq i (1+ i)<br/> ent (entget(ssname ss i))<br/> txt (cdr(assoc 1 ent))<br/> j (strlen txt)<br/> sl j)<br/> (while (and (> j 1) (/= (setq s1 (substr txt j 1)) ";")) (setq j (1- j)))<br/> (setq ent (subst (cons 1 (strcat (substr txt 1 j) news)) (assoc 1 ent) ent))<br/> (entmod ent)<br/> )<br/> ))<br/> ))<br/> (princ)<br/>)</p><p><br/>(defun chchar (ss eqq wt / tmp i) ;;<font color="#0000bb">晓东 zxq0220 2008.4.18 </font></p><p>(setq i 1 tmp "") <br/>(while (/= (setq s2 (substr ss i 1)) eqq) (setq tmp (strcat tmp s2) i (1+ i))) <br/>(strcat tmp wt (substr s1 (1+ i))) <br/>)</p> 本帖最后由 作者 于 2008-4-21 19:24:40 编辑
;替换分号后字符 明经 ZZXXQQ 2008.4.21
(defun c:tt ()
(if (setq news (getstring "\nEnter New string 输入新字串 <2]25> :")) (progn
(setq news (if (= (strlen news) 0) "2]25" news))
(while (wcmatch news "*`.*") (setq news (chchar news "." "]")))
(if (setq ss (ssget '((0 . "TEXT") (1 . "*;*")))) (progn
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i)
ent (entget(ssname ss i))
txt (cdr(assoc 1 ent))
j (strlen txt)
sl j)
(while (and (> j 1) (/= (setq s1 (substr txt j 1)) ";")) (setq j (1- j)))
(setq ent (subst (cons 1 (strcat (substr txt 1 j) news)) (assoc 1 ent) ent))
(entmod ent)
)
))
))
(princ)
)
<p>CAD2004测试,8楼程序(配合<font color="#0000bb">晓东 zxq0220的子程序)</font>可运行,但无法将点号“.”变成“]”输出。</p><p></p> 8楼已改。
页:
[1]
2