明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2117|回复: 0

[源码] 求助:修改开金工具的文字查找

[复制链接]
发表于 2014-7-10 09:54:34 | 显示全部楼层 |阅读模式
10明经币
本帖最后由 ymcui 于 2014-7-10 09:56 编辑

  1. *fr:dialog{
  2.   label="《開金工具箱》--(查找/替换)文字功能(适用于text、mtext)";
  3.   spacer;
  4.   :column{
  5.     :boxed_row{
  6.       :text_part{
  7.         label="查找文字:";
  8.         key="cz";
  9.       }
  10.       :edit_box{
  11.         key="text_find";
  12.         edit_limit=80;
  13.         edit_width=65;
  14.         value="";
  15.       }
  16.     }  
  17.     :boxed_row{
  18.       :text_part{
  19.         label="替换为:";
  20.         key="th";
  21.       }
  22.    
  23.       :edit_box{
  24.         key="text_replace";
  25.         edit_limit=80;
  26.         edit_width=65;
  27.         value="";
  28.       }
  29.     }
  30.     spacer;
  31.     :boxed_row{
  32.       :button{
  33.         label="查找";
  34.         key="select";
  35.       }
  36.     }
  37.     :boxed_row{
  38.       :text_part{
  39.         label="-->共找到()组字符";
  40.         key="t3";
  41.       }
  42.       :button{
  43.         label="缩放为(ZOOM)-->";
  44.         key="selecta";
  45.       }
  46.     }
  47.     :boxed_row{
  48.       :button{
  49.         label="修改";
  50.         key="selectb";
  51.       }
  52.       :button{
  53.         label="全部修改";
  54.         key="selectc";
  55.       }
  56.     }  
  57.   }
  58.   initial_focus=text_find;
  59.   spacer;
  60.   ok_cancel;
  61. }  


注:程序点击缩放时,点一次自动缩放下一个字符.谢谢
  1. ;查找/替换文字
  2. (defun c:KJ_WTH(/ msg_1 msg_2 dcl_file dcl_flag text_f text_r single ob_list ob_number

  3. temp text_code
  4.       text_o text_e text_h length_e length_f total_o total_t text_s text_c)
  5.      (setvar "cmdecho" 0) ;指令执行过程不响应
  6.      (PRINC "\n【開金工具箱】---查找/替换文字功能")
  7. (princ "\n-->请框选要查找替换的区域.....")
  8.   (defun dcl()
  9.     (setq dcl_file "fr")
  10.     (setq dcl_flag (load_dialog dcl_file))
  11.     (if (< dcl_flag 0) (exit))
  12.     (if (not (new_dialog "fr" dcl_flag)) (exit))
  13.     (set_tile "text_find" text_f)
  14.       (set_tile "text_replace" text_r)
  15.     (action_tile "text_find" "(setq text_f $$$$$$$$$$$$$$$$value)")
  16.       (action_tile "text_replace" "(setq text_r $$$$$$$$$$$$$$$$value)")
  17.     (action_tile "select" "(done_dialog 2)")
  18.     (action_tile "selecta" "(done_dialog 3)")
  19.     (action_tile "selectb" "(done_dialog 4)")
  20.     (action_tile "selectc" "(done_dialog 5)")
  21.     (action_tile "accept" "(do)")
  22.     (action_tile "cancel" "(done_dialog 0)")
  23.     (setq signal (start_dialog))
  24.     (if (= signal 2)
  25.       (setq ob_list (SSGET "x" '((0 . "*TEXT"))))
  26.     )
  27.     (if (= signal 3)
  28.       (command "zoom" "o" text_f "")
  29.     )
  30.     (if (= signal 4)
  31.       (command "zoom" "o" text_f "")
  32.     )
  33.     (if (= signal 5)
  34.       (command "zoom" "o" text_f "")
  35.     )
  36.   )
  37.   

  38.   (defun do()
  39.     (cond
  40.       ((= ob_list nil) (princ "\n未选择目标区域\n"))
  41.       ((= text_f "") (princ "\n未输入目标字符\n"))
  42.       ((= text_r "") (princ "\n未输入替代字符\n"))      
  43.       ((and (and (/= ob_list nil) (/= text_r "")) (/= text_f ""))

  44. (main))
  45.     )
  46.   )

  47.   (defun main()
  48.     (setq ob_number (sslength ob_list))
  49.     (setq temp 1)      
  50.     (setq total_o 0)
  51.     (setq total_t 0)
  52.     (repeat ob_number
  53.         (setq text_code (entget (ssname ob_list (- temp 1))))
  54.       (if
  55.         (or (= "TEXT" (cdr (assoc 0 text_code)))
  56.             (= "MTEXT" (cdr (assoc 0 text_code)))
  57.         )
  58.         (progn
  59.           (setq text_o (cdr (assoc 1 (entget (ssname ob_list (- temp

  60. 1))))))
  61.           (setq text_e text_o)
  62.           (setq text_h "")
  63.           (setq length_e (strlen text_e))
  64.           (setq length_f (strlen text_f))
  65.           (while
  66.             (and (<= length_f length_e) (/= length_e 0))
  67.             (setq text_s (substr text_e 1 length_f))
  68.             (if
  69.         (= text_s text_f)
  70.         (progn
  71.           (setq text_h (strcat text_h text_r))
  72.           (setq text_e (substr text_e (+ length_f 1)))
  73.           (setq total_t (+ total_t 1))
  74.         )
  75.         (progn
  76.           (setq text_s (substr text_e 1 1))
  77.           (setq text_h (strcat text_h text_s))
  78.           (setq text_e (substr text_e 2))
  79.         )
  80.                   )
  81.             (setq length_e (strlen text_e))
  82.           )
  83.           (setq text_c (strcat text_h text_e))
  84.           (if
  85.             (/= text_c text_o)
  86.             (progn
  87.               (setq text_code (subst (cons 1 text_c) (assoc 1

  88. text_code) text_code))
  89.               (entmod text_code)
  90.         (setq total_o (+ total_o 1))
  91.             )        
  92.           )
  93.         )  
  94.       )
  95.       (setq temp (+ 1 temp))
  96.     )
  97.     (done_dialog 1)
  98.   )

  99.   
  100.   (setq text_r "")
  101.     (setq text_f "")
  102.   (dcl)
  103.   (while (= signal 2) (dcl))
  104.     (if (/= signal 0)
  105.     (progn      
  106.       (princ "\n★★★欢迎使用--《開金工具箱》--★★★      共修改了

  107. ")
  108.       (princ total_t)
  109.       (princ "个文字")
  110.     )
  111.   )  
  112.   (unload_dialog dcl_flag)
  113.   (prin1)
  114. )

附件: 您需要 登录 才可以下载或查看,没有账号?注册
"觉得好,就打赏"
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 09:26 , Processed in 0.181694 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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