明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3528|回复: 8

[函数] 文字替换函数.

[复制链接]
发表于 2015-1-17 23:35:48 | 显示全部楼层 |阅读模式
  1. (defun cx-str-th (etext old new)
  2.   (setq  thln   (strlen old)
  3.     runstr ""
  4.   )
  5.   (while (> (strlen etext) 0)
  6.     (if  (= old (substr etext 1 thln))
  7.       (progn
  8.         (setq runstr (strcat runstr new))
  9.         (setq etext (substr etext (1+ thln)))
  10.       )
  11.       (progn
  12.         (setq runstr (strcat runstr (substr etext 1 1)))
  13.         (setq etext (substr etext 2))
  14.       )
  15.     )
  16.   )
  17.   runstr
  18. )
"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2015-1-17 23:36:40 | 显示全部楼层
正在准备功能.
'("1" "2" "3" "4") '("A" "B" "C" "D"))  批量替换.~
抛砖引玉.
 楼主| 发表于 2015-1-18 00:01:01 | 显示全部楼层
本帖最后由 鱼与熊掌 于 2015-1-19 00:42 编辑

目测成功了.
(cx-str-rep
    "af1fewr2gdfg6ggd3fgd2gfd4"
    '("1" "2" "3" "4")
    '("A" "B" "C" "D")
  )

=>"afAfewrBgdfg6ggdCfgdBgfdD"

;疯狂敛财,没用请不要下载.~




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2015-1-18 21:12:06 | 显示全部楼层
支持楼主做成能用的lisp,还有最好支持属性块
 楼主| 发表于 2015-1-19 00:15:26 | 显示全部楼层
bai2000 发表于 2015-1-18 21:12
支持楼主做成能用的lisp,还有最好支持属性块

已经做好了-.-    马上上传..   
 楼主| 发表于 2015-1-19 00:41:02 | 显示全部楼层
本帖最后由 鱼与熊掌 于 2015-1-19 00:49 编辑

画里面索引这种属性块时,有时候需要重新编号,那么就会非常麻烦.
或者排号的时候,比较麻烦,现在推出这个功能, 我觉得还行.
属于代码的引用实例.包括函数.
cx-reptext
;功能,替换文字或者属性块的文字.
;参数 ss 选择集或者图元表.
;oldstr 旧文字 支持单文本替换和集体替换如 "1" 或者'("1" "2" "3" "4")
;newstr新文字,同上                                       "A"  或者'("A" "B" "C" "D")
;工作中可能需要1>A 2>B 3>C 4>D.
那么使用传统的替换方式可能最后的结果需要多重转换,也就是变量转换的问题.
比如A=>1
后来1又被替换成C,最后造成结果不正确代码太长不好维护.

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2015-1-19 00:43:56 | 显示全部楼层
本帖最后由 鱼与熊掌 于 2015-1-19 00:47 编辑

;跟帖伪源码.
;上方演示图的伪源码.
;另外为替换文字函数的函数,支持属性块.
;函数Etype,Dxf,entmod,借用一部分E派函数.
  1. ;功能,索引加
  2. (defun c:jsy (/ *cx_jsyint attlst minx slst ss)
  3.   ;;;  (setq ss (ssget ))
  4.   (if (null *cx_jsyint)
  5.     (setq *cx_jsyint 1)
  6.   )
  7.   (while (progn
  8.       (setq ss
  9.         (cx-ssget (strcat "选择递增块,起始值:" (itoa *cx_jsyint) "\n")
  10.           (CX-LST+STR (CX-RANGE-STRNUM 1 100) " ")
  11.           '((0 . "INSERT"))
  12.         )
  13.       )
  14.       (cond
  15.         ((=
  16.             'str
  17.             (type ss)
  18.           )
  19.           (setq *cx_jsyint (atoi ss))
  20.           t
  21.         )
  22.         (ss
  23.           nil
  24.         )
  25.         (t t)
  26.       )
  27.     )
  28.   )
  29.   (if ss
  30.     (progn
  31.       (setq slst (cx-ss2en ss))
  32.       (setq attlst (mapcar '(lambda (x) (cx-Get-Attstr x)) slst))
  33.       (setq attlst (apply 'append attlst))
  34.       (setq attlst (VL-REMOVE-IF-NOT 'CX-STRISINT attlst))
  35.       (setq attlst (mapcar 'atoi attlst))
  36.       (setq minx (apply 'min attlst))
  37.       (cx-reptext
  38.         slst
  39.         (CX-RANGE-STRNUM minx (+ minx 3))
  40.         (CX-RANGE-STRNUM *cx_jsyint (+ *cx_jsyint 3))
  41.       )
  42.       (setq *cx_jsyint (+ 4 *cx_jsyint))
  43.     )
  44.   )
  45. )


  46. ;批量替换文本.
  47. (defun CX-reptext (SS     oldch   newch   /     ct0     ct1
  48.     ct2     edata   etext   newtext obj     readch
  49.     schct   ssl     subln   txtln
  50.   )
  51.   (if (/= 'list (type ss))
  52.     (setq ss (cx-ss2en ss))
  53.   )
  54.   (foreach x ss
  55.     (cond
  56.       ((cx-Etype x "*TEXT")
  57.         (cx-entmod x 1 (cx-str-th newch oldch (cx-dxf 1 x)))
  58.       )
  59.       ((cx-Etype x "INSERT")
  60.         (setq obj (zvla x))
  61.         (mapcar '(lambda  (att)
  62.             ;(cons (vla-get-TagString att) (vla-get-TextString att))
  63.             (vla-put-TextString
  64.               att
  65.               (cx-str-th newch
  66.                 oldch
  67.                 (vla-get-TextString
  68.                   att
  69.                 )
  70.               )
  71.             )
  72.             
  73.             
  74.           )
  75.           (vlax-invoke obj "GetAttributes")
  76.         )
  77.       )
  78.     )
  79.   )
  80. )
发表于 2017-12-4 11:39:08 | 显示全部楼层
我的为什么做不了这效果
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-16 22:12 , Processed in 0.191600 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表