输入触发输出
我想知道如何让一个变量决定另一个变量我希望能够改变这个代码,让旧字符串遍历所有分数
然后将新字符串更改为所有这些堆叠的对角分数
所以1/4会变成这个
{\H0.75x;\S1#4;}
和
所以3/8会变成这个
{\H0.75x;\S3#8;}
无需用户输入字符串
(defun c:superstr()
(setq olsosmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os (getstring "\nOld string: " t))))
(setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
(setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
) 我首先把代码分解成defuns,你的ssget基本上可以得到任何东西,然后在其他人忽略的对象类型TEXT、MTEXT或Blocks上使用cond。这样,您只需使用1个defun,而不是一个mega IF。同样,一个单独的defun,一旦你有了文本字符串,就会被调用,它有一系列的条件1/8 1/4 3/8 1/2等,并设置正确的多行文字字符串。我想说的是,你可以在defuns中调用defuns。
defun change text
defun ssget stuff
defun what is it
defun text option convert to mtext, defun change text
defun mtext get value, defun change text
defun insert get attributes, defun change text
program starts here
这段代码对于将旧字符串转换为您要查找的字符串非常有用:
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}"))) 对不起,我刚意识到我最初没有发布完整的代码
(defun c:superstr()
(setq olsosmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os (getstring "\nOld string: " t))))
(setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
(setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "DIMENSION" ; Look for DIMENSION entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
)
)
(if (> chm 1)
(princ (strcat "\nUpdated " (itoa chm) " text strings"))
(princ (strcat "\nUpdated " (itoa chm) " text string"))
)
(setvar "OSMODE" oldosmode)
(terpri)
)
;
(defun atext (num)
(cdr (assoc num d))
)
另外,我为自己糟糕的编码技巧道歉,但我不确定我会删除什么,或者在哪里添加你给我的这个替换函数?
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
任何愿意帮助的人 所以我想出了如何添加您提供的代码,使输入的分数替换为堆叠版本
以下是更新的代码:
(defun c:superstr()
(setq olsosmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os (getstring "\nOld string: " t))))
(setq nsl (strlen (setq ns os)))
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
(setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "DIMENSION" ; Look for DIMENSION entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
)
)
(if (> chm 1)
(princ (strcat "\nUpdated " (itoa chm) " text strings"))
(princ (strcat "\nUpdated " (itoa chm) " text string"))
)
(setvar "OSMODE" oldosmode)
(terpri)
)
;
(defun atext (num)
(cdr (assoc num d))
)
现在,我正在寻找一种方法来搜索所有分数,而不是输入字符串。。。
有什么方法可以一次将os设置为多个分数吗?
或者我必须设置某种从1/16到15/16的延续,因为我只需要改变16。。。 所以我得到了一个分数,用叠加的对角线代替。。。现在我只需要另外14个
请帮帮我。。。英雄联盟
(defun c:superstr()
(setq olsosmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os "1/4")))
(setq nsl (strlen (setq ns os)))
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}"))) (setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "DIMENSION" ; Look for DIMENSION entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
)
)
(if (> chm 1)
(princ (strcat "\nUpdated " (itoa chm) " text strings"))
(princ (strcat "\nUpdated " (itoa chm) " text string"))
)
(setvar "OSMODE" oldosmode)
(terpri)
)
;
(defun atext (num)
(cdr (assoc num d))
) 我曾尝试使用mapcar应用列表,但没有成功获得错误变量的结果。。。有人能告诉我我做错了什么并帮我修复吗?
(defun c:superstr()
(setq olsosmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os (mapcar 'yourfun stringlist))))
(setq nsl (strlen (setq ns os)))
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}"))) (setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "DIMENSION" ; Look for DIMENSION entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
)
)
(if (> chm 1)
(princ (strcat "\nUpdated " (itoa chm) " text strings"))
(princ (strcat "\nUpdated " (itoa chm) " text string"))
)
(setvar "OSMODE" oldosmode)
(terpri)
)
;
(defun atext (num)
(cdr (assoc num d))
)
;
(defun yourfun (os)
(setq stringlist '(list "1/4" "1/2"))
)
(defun c:superstr()
(setq p (ssget))
(if p
(progn
(setq osl (strlen (setq os " 1/4")))
(setq nsl (strlen (setq ns os)))
(if (vl-string-search "/" os)
(setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
(setq ns (vl-string-subst "" " " ns))
(setq l 0 chm 0 n (sslength p))
(setq adj
(cond
((/= osl nsl) (- nsl osl))
(T nsl)
)
)
(while (< l n)
(setq d (entget (setq e (ssname p l))))
(if (and (= (atext 0) "INSERT")(= (atext 66) 1))
(progn
(setq e (entnext e))
(while e
(setq d (entget e))
(cond
((= (atext 0) "ATTRIB")
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 d))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(cond
((= st os)
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t)
(setq si (+ si adj))
)
)
(setq si (1+ si))
)
(if chf
(progn
(setq d (subst (cons 1 s) as d))
(entmod d)
(entupd e)
(setq chm (1+ chm))
)
)
(setq e (entnext e))
)
((= (atext 0) "SEQEND")
(setq e nil))
(T (setq e (entnext e)))
)
)
)
)
(if (= "MTEXT" ; Look for MTEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "DIMENSION" ; Look for DIMENSION entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
)
)
(if (> chm 1)
(princ (strcat "\nUpdated " (itoa chm) " text strings"))
(princ (strcat "\nUpdated " (itoa chm) " text string"))
)
(terpri)
)
;
(defun atext (num)
(cdr (assoc num d))
)
页:
[1]