乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 37|回复: 7

[编程交流] 输入触发输出

[复制链接]

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 19:00:18 | 显示全部楼层 |阅读模式
我想知道如何让一个变量决定另一个变量
 
 
我希望能够改变这个代码,让旧字符串遍历所有分数
然后将新字符串更改为所有这些堆叠的对角分数
 
所以1/4会变成这个
{\H0.75x;\S1#4;}

所以3/8会变成这个
{\H0.75x;\S3#8;}
 
 
无需用户输入字符串
 
 
 
 
  1. (defun c:superstr()
  2.    (setq olsosmode (getvar "OSMODE"))
  3.    (setvar "OSMODE" 0)
  4.    (setq p (ssget))  
  5.    (if p
  6. (progn
  7.            (setq osl (strlen (setq os (getstring "\nOld string: " t))))
  8.            (setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
  9.     (setq l 0 chm 0 n (sslength p))
  10.     (setq adj
  11. (cond
  12.      ((/= osl nsl) (- nsl osl))
  13.      (T nsl)
  14. )
  15.     )
  16. (while (< l n)                  
  17.     (setq d (entget (setq e (ssname p l))))
  18.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  19. (progn
  20.      (setq e (entnext e))
  21.      (while e
  22.   (setq d (entget e))
  23.   (cond
  24.       ((= (atext 0) "ATTRIB")
  25.    (setq chf nil si 1)
  26.    (setq s (cdr (setq as (assoc 1 d))))
  27.    (while (= osl (setq sl (strlen
  28.        (setq st (substr s si osl)))))
  29.        (cond
  30.     ((= st os)
  31.         (setq s (strcat (substr s 1 (1- si)) ns
  32.         (substr s (+ si osl))))
  33.         (setq chf t)
  34.         (setq si (+ si adj))
  35.     )
  36.        )
  37.    (setq si (1+ si))
  38.       )
  39.       (if chf
  40.    (progn      
  41.        (setq d (subst (cons 1 s) as d))
  42.        (entmod d)      
  43.        (entupd e)      
  44.        (setq chm (1+ chm))
  45.    )
  46.       )
  47.       (setq e (entnext e))
  48.       )
  49.       ((= (atext 0) "SEQEND")
  50.    (setq e nil))
  51.       (T (setq e (entnext e)))
  52.                        )
  53.      )
  54. )
  55.     )
  56.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  57.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  58.                  (progn
  59.                     (setq chf nil si 1)
  60.                     (setq s (cdr (setq as (assoc 1 e))))
  61.                     (while (= osl (setq sl (strlen
  62.                        (setq st (substr s si osl)))))
  63.                        (if (= st os)
  64.                           (progn
  65.                              (setq s (strcat (substr s 1 (1- si)) ns
  66.                                        (substr s (+ si osl))))
  67.                           (setq chf t) ; Found old string
  68.                        (setq si (+ si nsl))
  69.                      )
  70.                      (setq si (1+ si))
  71.                  )
  72.               )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:12:38 | 显示全部楼层
我首先把代码分解成defuns,你的ssget基本上可以得到任何东西,然后在其他人忽略的对象类型TEXT、MTEXT或Blocks上使用cond。这样,您只需使用1个defun,而不是一个mega IF。同样,一个单独的defun,一旦你有了文本字符串,就会被调用,它有一系列的条件1/8 1/4 3/8 1/2等,并设置正确的多行文字字符串。我想说的是,你可以在defuns中调用defuns。
 
  1. defun change text
  2. defun ssget stuff
  3. defun what is it
  4. defun text option convert to mtext, defun change text
  5. defun mtext get value, defun change text
  6. defun insert get attributes, defun change text
  7. program starts here
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-5 19:21:04 | 显示全部楼层
这段代码对于将旧字符串转换为您要查找的字符串非常有用:
  1. (if (vl-string-search "/" os)
  2. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
回复

使用道具 举报

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 19:32:03 | 显示全部楼层
对不起,我刚意识到我最初没有发布完整的代码
 
  1. (defun c:superstr()
  2.    (setq olsosmode (getvar "OSMODE"))
  3.    (setvar "OSMODE" 0)
  4.    (setq p (ssget))  
  5.    (if p
  6. (progn
  7.            (setq osl (strlen (setq os (getstring "\nOld string: " t))))
  8.            (setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
  9.     (setq l 0 chm 0 n (sslength p))
  10.     (setq adj
  11. (cond
  12.      ((/= osl nsl) (- nsl osl))
  13.      (T nsl)
  14. )
  15.     )
  16. (while (< l n)                  
  17.     (setq d (entget (setq e (ssname p l))))
  18.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  19. (progn
  20.      (setq e (entnext e))
  21.      (while e
  22.   (setq d (entget e))
  23.   (cond
  24.       ((= (atext 0) "ATTRIB")
  25.    (setq chf nil si 1)
  26.    (setq s (cdr (setq as (assoc 1 d))))
  27.    (while (= osl (setq sl (strlen
  28.        (setq st (substr s si osl)))))
  29.        (cond
  30.     ((= st os)
  31.         (setq s (strcat (substr s 1 (1- si)) ns
  32.         (substr s (+ si osl))))
  33.         (setq chf t)
  34.         (setq si (+ si adj))
  35.     )
  36.        )
  37.    (setq si (1+ si))
  38.       )
  39.       (if chf
  40.    (progn      
  41.        (setq d (subst (cons 1 s) as d))
  42.        (entmod d)      
  43.        (entupd e)      
  44.        (setq chm (1+ chm))
  45.    )
  46.       )
  47.       (setq e (entnext e))
  48.       )
  49.       ((= (atext 0) "SEQEND")
  50.    (setq e nil))
  51.       (T (setq e (entnext e)))
  52.                        )
  53.      )
  54. )
  55.     )
  56.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  57.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  58.                  (progn
  59.                     (setq chf nil si 1)
  60.                     (setq s (cdr (setq as (assoc 1 e))))
  61.                     (while (= osl (setq sl (strlen
  62.                        (setq st (substr s si osl)))))
  63.                        (if (= st os)
  64.                           (progn
  65.                              (setq s (strcat (substr s 1 (1- si)) ns
  66.                                        (substr s (+ si osl))))
  67.                           (setq chf t) ; Found old string
  68.                        (setq si (+ si nsl))
  69.                      )
  70.                      (setq si (1+ si))
  71.                  )
  72.               )
  73.               (if chf (progn        ; Substitute new string for old
  74.                  (setq e (subst (cons 1 s) as e))
  75.                  (entmod e)         ; Modify the TEXT entity
  76.                  (setq chm (1+ chm))
  77.               ))
  78.            )
  79.         )
  80.     (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
  81.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  82.                  (progn
  83.                     (setq chf nil si 1)
  84.                     (setq s (cdr (setq as (assoc 1 e))))
  85.                     (while (= osl (setq sl (strlen
  86.                        (setq st (substr s si osl)))))
  87.                        (if (= st os)
  88.                           (progn
  89.                              (setq s (strcat (substr s 1 (1- si)) ns
  90.                                        (substr s (+ si osl))))
  91.                           (setq chf t) ; Found old string
  92.                        (setq si (+ si nsl))
  93.                      )
  94.                      (setq si (1+ si))
  95.                  )
  96.               )
  97.               (if chf (progn        ; Substitute new string for old
  98.                  (setq e (subst (cons 1 s) as e))
  99.                  (entmod e)         ; Modify the TEXT entity
  100.                  (setq chm (1+ chm))
  101.               ))
  102.            )
  103.         )
  104.     (if (= "TEXT"            ; Look for TEXT entity type (group 0)
  105.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  106.                  (progn
  107.                     (setq chf nil si 1)
  108.                     (setq s (cdr (setq as (assoc 1 e))))
  109.                     (while (= osl (setq sl (strlen
  110.                        (setq st (substr s si osl)))))
  111.                        (if (= st os)
  112.                           (progn
  113.                              (setq s (strcat (substr s 1 (1- si)) ns
  114.                                        (substr s (+ si osl))))
  115.                           (setq chf t) ; Found old string
  116.                        (setq si (+ si nsl))
  117.                      )
  118.                      (setq si (1+ si))
  119.                  )
  120.               )
  121.               (if chf (progn        ; Substitute new string for old
  122.                  (setq e (subst (cons 1 s) as e))
  123.                  (entmod e)         ; Modify the TEXT entity
  124.                  (setq chm (1+ chm))
  125.               ))
  126.            )
  127.         )
  128.     (setq l (1+ l))
  129. )
  130. )
  131.    )
  132.    (if (> chm 1)
  133.       (princ (strcat "\nUpdated " (itoa chm) " text strings"))
  134.       (princ (strcat "\nUpdated " (itoa chm) " text string"))
  135.    )
  136.    (setvar "OSMODE" oldosmode)
  137.    (terpri)
  138. )
  139. ;
  140. (defun atext (num)
  141.   (cdr (assoc num d))
  142. )

 
另外,我为自己糟糕的编码技巧道歉,但我不确定我会删除什么,或者在哪里添加你给我的这个替换函数?
 
  1. (if (vl-string-search "/" os)
  2. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))

 
任何愿意帮助的人
回复

使用道具 举报

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 19:39:24 | 显示全部楼层
所以我想出了如何添加您提供的代码,使输入的分数替换为堆叠版本
 
 
以下是更新的代码:
  1. (defun c:superstr()
  2.    (setq olsosmode (getvar "OSMODE"))
  3.    (setvar "OSMODE" 0)
  4.    (setq p (ssget))  
  5.    (if p
  6. (progn
  7.            (setq osl (strlen (setq os (getstring "\nOld string: " t))))
  8.            (setq nsl (strlen (setq ns os)))
  9.      (if (vl-string-search "/" os)
  10. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
  11.     (setq l 0 chm 0 n (sslength p))
  12.     (setq adj
  13. (cond
  14.      ((/= osl nsl) (- nsl osl))
  15.      (T nsl)
  16. )
  17.     )
  18. (while (< l n)                  
  19.     (setq d (entget (setq e (ssname p l))))
  20.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  21. (progn
  22.      (setq e (entnext e))
  23.      (while e
  24.   (setq d (entget e))
  25.   (cond
  26.       ((= (atext 0) "ATTRIB")
  27.    (setq chf nil si 1)
  28.    (setq s (cdr (setq as (assoc 1 d))))
  29.    (while (= osl (setq sl (strlen
  30.        (setq st (substr s si osl)))))
  31.        (cond
  32.     ((= st os)
  33.         (setq s (strcat (substr s 1 (1- si)) ns
  34.         (substr s (+ si osl))))
  35.         (setq chf t)
  36.         (setq si (+ si adj))
  37.     )
  38.        )
  39.    (setq si (1+ si))
  40.       )
  41.       (if chf
  42.    (progn      
  43.        (setq d (subst (cons 1 s) as d))
  44.        (entmod d)      
  45.        (entupd e)      
  46.        (setq chm (1+ chm))
  47.    )
  48.       )
  49.       (setq e (entnext e))
  50.       )
  51.       ((= (atext 0) "SEQEND")
  52.    (setq e nil))
  53.       (T (setq e (entnext e)))
  54.                        )
  55.      )
  56. )
  57.     )
  58.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  59.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  60.                  (progn
  61.                     (setq chf nil si 1)
  62.                     (setq s (cdr (setq as (assoc 1 e))))
  63.                     (while (= osl (setq sl (strlen
  64.                        (setq st (substr s si osl)))))
  65.                        (if (= st os)
  66.                           (progn
  67.                              (setq s (strcat (substr s 1 (1- si)) ns
  68.                                        (substr s (+ si osl))))
  69.                           (setq chf t) ; Found old string
  70.                        (setq si (+ si nsl))
  71.                      )
  72.                      (setq si (1+ si))
  73.                  )
  74.               )
  75.               (if chf (progn        ; Substitute new string for old
  76.                  (setq e (subst (cons 1 s) as e))
  77.                  (entmod e)         ; Modify the TEXT entity
  78.                  (setq chm (1+ chm))
  79.               ))
  80.            )
  81.         )
  82.     (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
  83.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  84.                  (progn
  85.                     (setq chf nil si 1)
  86.                     (setq s (cdr (setq as (assoc 1 e))))
  87.                     (while (= osl (setq sl (strlen
  88.                        (setq st (substr s si osl)))))
  89.                        (if (= st os)
  90.                           (progn
  91.                              (setq s (strcat (substr s 1 (1- si)) ns
  92.                                        (substr s (+ si osl))))
  93.                           (setq chf t) ; Found old string
  94.                        (setq si (+ si nsl))
  95.                      )
  96.                      (setq si (1+ si))
  97.                  )
  98.               )
  99.               (if chf (progn        ; Substitute new string for old
  100.                  (setq e (subst (cons 1 s) as e))
  101.                  (entmod e)         ; Modify the TEXT entity
  102.                  (setq chm (1+ chm))
  103.               ))
  104.            )
  105.         )
  106.     (if (= "TEXT"            ; Look for TEXT entity type (group 0)
  107.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  108.                  (progn
  109.                     (setq chf nil si 1)
  110.                     (setq s (cdr (setq as (assoc 1 e))))
  111.                     (while (= osl (setq sl (strlen
  112.                        (setq st (substr s si osl)))))
  113.                        (if (= st os)
  114.                           (progn
  115.                              (setq s (strcat (substr s 1 (1- si)) ns
  116.                                        (substr s (+ si osl))))
  117.                           (setq chf t) ; Found old string
  118.                        (setq si (+ si nsl))
  119.                      )
  120.                      (setq si (1+ si))
  121.                  )
  122.               )
  123.               (if chf (progn        ; Substitute new string for old
  124.                  (setq e (subst (cons 1 s) as e))
  125.                  (entmod e)         ; Modify the TEXT entity
  126.                  (setq chm (1+ chm))
  127.               ))
  128.            )
  129.         )
  130.     (setq l (1+ l))
  131. )
  132. )
  133.    )
  134.    (if (> chm 1)
  135.       (princ (strcat "\nUpdated " (itoa chm) " text strings"))
  136.       (princ (strcat "\nUpdated " (itoa chm) " text string"))
  137.    )
  138.    (setvar "OSMODE" oldosmode)
  139.    (terpri)
  140. )
  141. ;
  142. (defun atext (num)
  143.   (cdr (assoc num d))
  144. )

 
 
现在,我正在寻找一种方法来搜索所有分数,而不是输入字符串。。。
 
 
有什么方法可以一次将os设置为多个分数吗?
 
 
或者我必须设置某种从1/16到15/16的延续,因为我只需要改变16。。。
回复

使用道具 举报

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 19:51:01 | 显示全部楼层
所以我得到了一个分数,用叠加的对角线代替。。。现在我只需要另外14个
 
请帮帮我。。。英雄联盟
 
 
  1. (defun c:superstr()
  2.    (setq olsosmode (getvar "OSMODE"))
  3.    (setvar "OSMODE" 0)
  4.    (setq p (ssget))  
  5.    (if p
  6. (progn
  7.            (setq osl (strlen (setq os "1/4")))
  8.            (setq nsl (strlen (setq ns os)))
  9.      (if (vl-string-search "/" os)
  10. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))     (setq l 0 chm 0 n (sslength p))
  11.     (setq adj
  12. (cond
  13.      ((/= osl nsl) (- nsl osl))
  14.      (T nsl)
  15. )
  16.     )
  17. (while (< l n)                  
  18.     (setq d (entget (setq e (ssname p l))))
  19.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  20. (progn
  21.      (setq e (entnext e))
  22.      (while e
  23.   (setq d (entget e))
  24.   (cond
  25.       ((= (atext 0) "ATTRIB")
  26.    (setq chf nil si 1)
  27.    (setq s (cdr (setq as (assoc 1 d))))
  28.    (while (= osl (setq sl (strlen
  29.        (setq st (substr s si osl)))))
  30.        (cond
  31.     ((= st os)
  32.         (setq s (strcat (substr s 1 (1- si)) ns
  33.         (substr s (+ si osl))))
  34.         (setq chf t)
  35.         (setq si (+ si adj))
  36.     )
  37.        )
  38.    (setq si (1+ si))
  39.       )
  40.       (if chf
  41.    (progn      
  42.        (setq d (subst (cons 1 s) as d))
  43.        (entmod d)      
  44.        (entupd e)      
  45.        (setq chm (1+ chm))
  46.    )
  47.       )
  48.       (setq e (entnext e))
  49.       )
  50.       ((= (atext 0) "SEQEND")
  51.    (setq e nil))
  52.       (T (setq e (entnext e)))
  53.                        )
  54.      )
  55. )
  56.     )
  57.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  58.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  59.                  (progn
  60.                     (setq chf nil si 1)
  61.                     (setq s (cdr (setq as (assoc 1 e))))
  62.                     (while (= osl (setq sl (strlen
  63.                        (setq st (substr s si osl)))))
  64.                        (if (= st os)
  65.                           (progn
  66.                              (setq s (strcat (substr s 1 (1- si)) ns
  67.                                        (substr s (+ si osl))))
  68.                           (setq chf t) ; Found old string
  69.                        (setq si (+ si nsl))
  70.                      )
  71.                      (setq si (1+ si))
  72.                  )
  73.               )
  74.               (if chf (progn        ; Substitute new string for old
  75.                  (setq e (subst (cons 1 s) as e))
  76.                  (entmod e)         ; Modify the TEXT entity
  77.                  (setq chm (1+ chm))
  78.               ))
  79.            )
  80.         )
  81.     (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
  82.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  83.                  (progn
  84.                     (setq chf nil si 1)
  85.                     (setq s (cdr (setq as (assoc 1 e))))
  86.                     (while (= osl (setq sl (strlen
  87.                        (setq st (substr s si osl)))))
  88.                        (if (= st os)
  89.                           (progn
  90.                              (setq s (strcat (substr s 1 (1- si)) ns
  91.                                        (substr s (+ si osl))))
  92.                           (setq chf t) ; Found old string
  93.                        (setq si (+ si nsl))
  94.                      )
  95.                      (setq si (1+ si))
  96.                  )
  97.               )
  98.               (if chf (progn        ; Substitute new string for old
  99.                  (setq e (subst (cons 1 s) as e))
  100.                  (entmod e)         ; Modify the TEXT entity
  101.                  (setq chm (1+ chm))
  102.               ))
  103.            )
  104.         )
  105.     (if (= "TEXT"            ; Look for TEXT entity type (group 0)
  106.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  107.                  (progn
  108.                     (setq chf nil si 1)
  109.                     (setq s (cdr (setq as (assoc 1 e))))
  110.                     (while (= osl (setq sl (strlen
  111.                        (setq st (substr s si osl)))))
  112.                        (if (= st os)
  113.                           (progn
  114.                              (setq s (strcat (substr s 1 (1- si)) ns
  115.                                        (substr s (+ si osl))))
  116.                           (setq chf t) ; Found old string
  117.                        (setq si (+ si nsl))
  118.                      )
  119.                      (setq si (1+ si))
  120.                  )
  121.               )
  122.               (if chf (progn        ; Substitute new string for old
  123.                  (setq e (subst (cons 1 s) as e))
  124.                  (entmod e)         ; Modify the TEXT entity
  125.                  (setq chm (1+ chm))
  126.               ))
  127.            )
  128.         )
  129.     (setq l (1+ l))
  130. )
  131. )
  132.    )
  133.    (if (> chm 1)
  134.       (princ (strcat "\nUpdated " (itoa chm) " text strings"))
  135.       (princ (strcat "\nUpdated " (itoa chm) " text string"))
  136.    )
  137.    (setvar "OSMODE" oldosmode)
  138.    (terpri)
  139. )
  140. ;
  141. (defun atext (num)
  142.   (cdr (assoc num d))
  143. )
回复

使用道具 举报

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 19:53:58 | 显示全部楼层
我曾尝试使用mapcar应用列表,但没有成功获得错误变量的结果。。。有人能告诉我我做错了什么并帮我修复吗?
 
  1. (defun c:superstr()
  2.    (setq olsosmode (getvar "OSMODE"))
  3.    (setvar "OSMODE" 0)
  4.    (setq p (ssget))
  5.    (if p
  6. (progn
  7.            (setq osl (strlen (setq os (mapcar 'yourfun stringlist))))
  8.            (setq nsl (strlen (setq ns os)))
  9.      (if (vl-string-search "/" os)
  10. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))     (setq l 0 chm 0 n (sslength p))
  11.     (setq adj
  12. (cond
  13.      ((/= osl nsl) (- nsl osl))
  14.      (T nsl)
  15. )
  16.     )
  17. (while (< l n)                  
  18.     (setq d (entget (setq e (ssname p l))))
  19.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  20. (progn
  21.      (setq e (entnext e))
  22.      (while e
  23.   (setq d (entget e))
  24.   (cond
  25.       ((= (atext 0) "ATTRIB")
  26.    (setq chf nil si 1)
  27.    (setq s (cdr (setq as (assoc 1 d))))
  28.    (while (= osl (setq sl (strlen
  29.        (setq st (substr s si osl)))))
  30.        (cond
  31.     ((= st os)
  32.         (setq s (strcat (substr s 1 (1- si)) ns
  33.         (substr s (+ si osl))))
  34.         (setq chf t)
  35.         (setq si (+ si adj))
  36.     )
  37.        )
  38.    (setq si (1+ si))
  39.       )
  40.       (if chf
  41.    (progn      
  42.        (setq d (subst (cons 1 s) as d))
  43.        (entmod d)      
  44.        (entupd e)      
  45.        (setq chm (1+ chm))
  46.    )
  47.       )
  48.       (setq e (entnext e))
  49.       )
  50.       ((= (atext 0) "SEQEND")
  51.    (setq e nil))
  52.       (T (setq e (entnext e)))
  53.                        )
  54.      )
  55. )
  56.     )
  57.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  58.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  59.                  (progn
  60.                     (setq chf nil si 1)
  61.                     (setq s (cdr (setq as (assoc 1 e))))
  62.                     (while (= osl (setq sl (strlen
  63.                        (setq st (substr s si osl)))))
  64.                        (if (= st os)
  65.                           (progn
  66.                              (setq s (strcat (substr s 1 (1- si)) ns
  67.                                        (substr s (+ si osl))))
  68.                           (setq chf t) ; Found old string
  69.                        (setq si (+ si nsl))
  70.                      )
  71.                      (setq si (1+ si))
  72.                  )
  73.               )
  74.               (if chf (progn        ; Substitute new string for old
  75.                  (setq e (subst (cons 1 s) as e))
  76.                  (entmod e)         ; Modify the TEXT entity
  77.                  (setq chm (1+ chm))
  78.               ))
  79.            )
  80.         )
  81.     (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
  82.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  83.                  (progn
  84.                     (setq chf nil si 1)
  85.                     (setq s (cdr (setq as (assoc 1 e))))
  86.                     (while (= osl (setq sl (strlen
  87.                        (setq st (substr s si osl)))))
  88.                        (if (= st os)
  89.                           (progn
  90.                              (setq s (strcat (substr s 1 (1- si)) ns
  91.                                        (substr s (+ si osl))))
  92.                           (setq chf t) ; Found old string
  93.                        (setq si (+ si nsl))
  94.                      )
  95.                      (setq si (1+ si))
  96.                  )
  97.               )
  98.               (if chf (progn        ; Substitute new string for old
  99.                  (setq e (subst (cons 1 s) as e))
  100.                  (entmod e)         ; Modify the TEXT entity
  101.                  (setq chm (1+ chm))
  102.               ))
  103.            )
  104.         )
  105.     (if (= "TEXT"            ; Look for TEXT entity type (group 0)
  106.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  107.                  (progn
  108.                     (setq chf nil si 1)
  109.                     (setq s (cdr (setq as (assoc 1 e))))
  110.                     (while (= osl (setq sl (strlen
  111.                        (setq st (substr s si osl)))))
  112.                        (if (= st os)
  113.                           (progn
  114.                              (setq s (strcat (substr s 1 (1- si)) ns
  115.                                        (substr s (+ si osl))))
  116.                           (setq chf t) ; Found old string
  117.                        (setq si (+ si nsl))
  118.                      )
  119.                      (setq si (1+ si))
  120.                  )
  121.               )
  122.               (if chf (progn        ; Substitute new string for old
  123.                  (setq e (subst (cons 1 s) as e))
  124.                  (entmod e)         ; Modify the TEXT entity
  125.                  (setq chm (1+ chm))
  126.               ))
  127.            )
  128.         )
  129.     (setq l (1+ l))
  130. )
  131. )
  132.    )
  133.    (if (> chm 1)
  134.       (princ (strcat "\nUpdated " (itoa chm) " text strings"))
  135.       (princ (strcat "\nUpdated " (itoa chm) " text string"))
  136.    )
  137.    (setvar "OSMODE" oldosmode)
  138.    (terpri)
  139. )
  140. ;
  141. (defun atext (num)
  142.   (cdr (assoc num d))
  143. )
  144. ;
  145. (defun yourfun (os)
  146. (setq stringlist '(list "1/4" "1/2"))
  147. )
回复

使用道具 举报

28

主题

87

帖子

37

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
167
发表于 2022-7-5 20:05:20 | 显示全部楼层
  1. (defun c:superstr()
  2.    (setq p (ssget))  
  3.    (if p
  4. (progn
  5.           (setq osl (strlen (setq os " 1/4")))
  6.            (setq nsl (strlen (setq ns os)))      
  7.      (if (vl-string-search "/" os)
  8. (setq ns (strcat "{\\H0.75x;\\S" (vl-string-subst "#" "/" os 0) ";}")))
  9. (setq ns (vl-string-subst "" " " ns))     
  10. (setq l 0 chm 0 n (sslength p))
  11.     (setq adj
  12. (cond
  13.      ((/= osl nsl) (- nsl osl))
  14.      (T nsl)
  15. )
  16.     )
  17. (while (< l n)                  
  18.     (setq d (entget (setq e (ssname p l))))
  19.     (if (and (= (atext 0) "INSERT")(= (atext 66) 1))
  20. (progn
  21.      (setq e (entnext e))
  22.      (while e
  23.   (setq d (entget e))
  24.   (cond
  25.       ((= (atext 0) "ATTRIB")
  26.    (setq chf nil si 1)
  27.    (setq s (cdr (setq as (assoc 1 d))))
  28.    (while (= osl (setq sl (strlen
  29.        (setq st (substr s si osl)))))
  30.        (cond
  31.     ((= st os)
  32.         (setq s (strcat (substr s 1 (1- si)) ns
  33.         (substr s (+ si osl))))
  34.         (setq chf t)
  35.         (setq si (+ si adj))
  36.     )
  37.        )
  38.    (setq si (1+ si))
  39.       )
  40.       (if chf
  41.    (progn      
  42.        (setq d (subst (cons 1 s) as d))
  43.        (entmod d)      
  44.        (entupd e)      
  45.        (setq chm (1+ chm))
  46.    )
  47.       )
  48.       (setq e (entnext e))
  49.       )
  50.       ((= (atext 0) "SEQEND")
  51.    (setq e nil))
  52.       (T (setq e (entnext e)))
  53.                        )
  54.      )
  55. )
  56.     )
  57.            (if (= "MTEXT"            ; Look for MTEXT entity type (group 0)
  58.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  59.                  (progn
  60.                     (setq chf nil si 1)
  61.                     (setq s (cdr (setq as (assoc 1 e))))
  62.                     (while (= osl (setq sl (strlen
  63.                        (setq st (substr s si osl)))))
  64.                        (if (= st os)
  65.                           (progn
  66.                              (setq s (strcat (substr s 1 (1- si)) ns
  67.                                        (substr s (+ si osl))))
  68.                           (setq chf t) ; Found old string
  69.                        (setq si (+ si nsl))
  70.                      )
  71.                      (setq si (1+ si))
  72.                  )
  73.               )
  74.               (if chf (progn        ; Substitute new string for old
  75.                  (setq e (subst (cons 1 s) as e))
  76.                  (entmod e)         ; Modify the TEXT entity
  77.                  (setq chm (1+ chm))
  78.               ))
  79.            )
  80.         )
  81.     (if (= "DIMENSION"            ; Look for DIMENSION entity type (group 0)
  82.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  83.                  (progn
  84.                     (setq chf nil si 1)
  85.                     (setq s (cdr (setq as (assoc 1 e))))
  86.                     (while (= osl (setq sl (strlen
  87.                        (setq st (substr s si osl)))))
  88.                        (if (= st os)
  89.                           (progn
  90.                              (setq s (strcat (substr s 1 (1- si)) ns
  91.                                        (substr s (+ si osl))))
  92.                           (setq chf t) ; Found old string
  93.                        (setq si (+ si nsl))
  94.                      )
  95.                      (setq si (1+ si))
  96.                  )
  97.               )
  98.               (if chf (progn        ; Substitute new string for old
  99.                  (setq e (subst (cons 1 s) as e))
  100.                  (entmod e)         ; Modify the TEXT entity
  101.                  (setq chm (1+ chm))
  102.               ))
  103.            )
  104.         )
  105.     (if (= "TEXT"            ; Look for TEXT entity type (group 0)
  106.               (cdr (assoc 0 (setq e (entget (ssname p l))))))
  107.                  (progn
  108.                     (setq chf nil si 1)
  109.                     (setq s (cdr (setq as (assoc 1 e))))
  110.                     (while (= osl (setq sl (strlen
  111.                        (setq st (substr s si osl)))))
  112.                        (if (= st os)
  113.                           (progn
  114.                              (setq s (strcat (substr s 1 (1- si)) ns
  115.                                        (substr s (+ si osl))))
  116.                           (setq chf t) ; Found old string
  117.                        (setq si (+ si nsl))
  118.                      )
  119.                      (setq si (1+ si))
  120.                  )
  121.               )
  122.               (if chf (progn        ; Substitute new string for old
  123.                  (setq e (subst (cons 1 s) as e))
  124.                  (entmod e)         ; Modify the TEXT entity
  125.                  (setq chm (1+ chm))
  126.               ))
  127.            )
  128.         )
  129.     (setq l (1+ l))
  130. )
  131. )
  132.     )
  133.     (if (> chm 1)
  134.        (princ (strcat "\nUpdated " (itoa chm) " text strings"))
  135.        (princ (strcat "\nUpdated " (itoa chm) " text string"))
  136.     )
  137.     (terpri)
  138. )
  139. ;
  140. (defun atext (num)
  141.   (cdr (assoc num d))
  142. )
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 13:28 , Processed in 0.503101 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表