乐筑天下

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

[编程交流] 需要帮助改进Quic

[复制链接]

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 20:18:17 | 显示全部楼层 |阅读模式
在我的工作过程中发现了这个由马克·梅西尔(MarkMercier)又称Freerefill)编写的“查找文本”lisp。
 
http://www.cadtutor.net/forum/showthread.php?35933-有史以来最好的文本查找和替换LISP。。。
 
我猜他不再浏览这里了。
 
我发现它非常有用&没有对话框,速度很快,因为它会减慢我的速度。正在使用autocad find命令&与此相比,速度要快得多。
 
我看到了它可以进一步提高的潜力,尤其是在速度方面。
 
因此,我想知道是否有人可以帮助调整lisp,以便:-
1) “查找”可以是默认选择。
因此,在运行命令后,我们可以开始键入我们想要查找的单词。
 
2) 它可以搜索整个单词
目前,它似乎像一个通配符一样搜索文本,我不得不循环浏览。我想这将是一个很好的选择,但只有当把*。
 
我希望它可以调整为默认情况下搜索整个单词。
 
老实说,这是一个非常好的Lisp程序。
 
希望有能力的人能看到它的潜力和改进建议
 
谢谢
 
这是代码
 
  1. ;-============-;
  2. ;- Text  Find -;
  3. ;-    *~*     -;
  4. ;  Written by -;
  5. ; Mark Mercier ;
  6. ;   05-06-09   ;
  7. ;-============-;
  8. ; Improvements:
  9. ; Text within blocks
  10. ; Improved selection set.. maybe do away with the whole "list" thing and go straight VLA
  11. (defun c:tfind()
  12. (tfindfun nil nil 0)
  13. )
  14. (defun tfindfun(inputF inputR caseSn / goto goWhile strinF strinR selSet selTxt searep case count error)
  15. ; 01 Create selection set. GOTO 02 if success, or GOTO 08 if fail
  16. ; 02 Check passed input. If both nil, GOTO 03. If first string and second nil, GOTO 06. If both strings, GOTO 07. Otherwise, return error and GOTO 08
  17. ; 03 Display menus and obtain data from user. If Search, GOTO 04. If Replace, GOTO 05
  18. ; 04 Search option selected. Prompt user for single search term. GOTO 06
  19. ; 05 Replace option selected. Prompt user for search term and replace term. GOTO 07
  20. ; 06 One string has been passed. Assume automatic search. Run same as current (tfind). GOTO FINISH
  21. ; 07 Two strings have been passed. Assume automatic replace. Pass both strings to (replace) function. GOTO FINISH
  22. ; 08 FINISH. Return errors if needed. End loop and program.
  23. (vl-load-com)
  24. (setq goTo 1)
  25. (setq goWhile 1)
  26. (setq count 0)
  27. (if (not (mlml (list caseSn) (list 0 1))) (progn (setq goWhile nil) (princ "\nCase selection not recognized.")))
  28. (if (= caseSn 0) (setq case "N") (setq case "Y"))
  29. (while goWhile
  30.    (cond
  31.      ((= goTo 1)
  32.       (setq selSet (extTxtPt (ssget "_X" (list (cons -4 "<OR") (cons 0 "TEXT,MTEXT") (cons -4 "<AND") (cons 0 "INSERT") (cons 66 1) (cons -4 "AND>") (cons -4 "OR>")))))
  33.       (if selSet (setq goTo 2) (setq error "\nSelection set not found." goTo )
  34.       )
  35.      ((= goTo 2)
  36.       ; Check input, pass to whatever.
  37.       (cond
  38.     ((and (= inputF nil) (= inputR nil))
  39.      (setq goTo 3)
  40.      )
  41.     ((and (= (type inputF) 'STR) (= inputR nil))
  42.      (setq strinF inputF)
  43.      (setq goTo 6)
  44.      )
  45.     ((and (= (type inputF) 'STR) (= (type inputR) 'STR))
  46.      (setq strinF inputF)
  47.      (setq strinR inputR)
  48.      (setq goTo 7)
  49.      )
  50.     (t
  51.      (setq error "\nPassed arguments are not accepted.")
  52.      (setq goTo
  53.      )
  54.     )
  55.       )
  56.      ((= goTo 3)
  57.       ; Obtain desired option from user
  58.       (while (not (mlml (list (setq searep (strcase (getstring nil "\nSelect option [Find/Replace/Quit/Case]: "))))
  59.                 (list "F" "FIND" "R" "REPLACE" "Q" "QUIT" "C" "CASE")
  60.                 ))
  61.     )
  62.       (cond
  63.     ((mlml (list searep) (list "F" "FIND"))
  64.      (setq goTo 4)
  65.      )
  66.     ((mlml (list searep) (list "R" "REPLACE"))
  67.      (setq goTo 5)
  68.      )
  69.     ((mlml (list searep) (list "Q" "QUIT"))
  70.      (setq goTo
  71.      )
  72.     ((mlml (list searep) (list "C" "CASE"))
  73.      (while (not (mlml (list (setq case (strcase (getstring nil "\nCase sensitive? [Yes/No]: "))))
  74.                    (list "Y" "YES" "N" "NO")
  75.                    ))
  76.        )
  77.      )
  78.     )
  79.       )
  80.      ((= goTo 4)
  81.       ; Obtain search string from user, set to strinF
  82.       (while (eq "" (setq strinF (getstring T "\nEnter search term: "))))
  83.       (setq goTo 6)
  84.       )
  85.      ((= goTo 5)
  86.       ; Obtain search string and replace string from user, set to strinF and strinR respectively
  87.       (while (eq "" (setq strinF (getstring T "\nEnter find term: "))))
  88.       (while (eq "" (setq strinR (getstring T "\nEnter replace term: "))))
  89.       (setq goTo 7)
  90.       )
  91.      ((= goTo 6)
  92.       ; Search drawing for strinF
  93.       (cond
  94.     ((mlml (list case) (list "Y" "YES"))
  95.      ; Compare using (vl-string-search strinF input), view selection
  96.      ; use "while" to get all search occurances
  97.      (foreach selVar selSet
  98.        (if (vl-string-search strinF (nth 0 selVar))
  99.          (progn
  100.        (setq count (1+ count))
  101.        (if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
  102.        (command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar)))
  103.        (getstring "\nPress 'Enter' to continue: ")
  104.        )
  105.          )
  106.        )
  107.      )
  108.     ((mlml (list case) (list "N" "NO"))
  109.      ; Compare using (vl-string-search (strcase strinF) (strcase input)), view selection
  110.      ; use "while" to get all search occurances
  111.      (foreach selVar selSet
  112.        (if (vl-string-search (strcase strinF) (strcase (nth 0 selVar)))
  113.          (progn
  114.        (setq count (1+ count))
  115.        (if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
  116.        (command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar)))
  117.        (getstring "\nPress 'Enter' to continue: ")
  118.        )
  119.          )
  120.        )
  121.      )
  122.     )
  123.       (if (= count 0) (setq error "\nNo matches found.") (setq error (strcat (itoa count) " matches found.")))
  124.       (setq goTo
  125.       )
  126.      ((= goTo 7)
  127.       ; Replace strinF with strinR
  128.       (cond
  129.     ((mlml (list case) (list "Y" "YES"))
  130.      ; Compare using (vl-search-string strinF input), modify using (vl-string-subst) within a while loop
  131.      (foreach selVar selSet
  132.        (setq selTxt (nth 0 selVar))
  133.        (setq seaLoc 0)
  134.        (while (setq seaLoc (vl-string-search strinF selTxt seaLoc))
  135.          (setq selTxt (vl-string-subst strinR strinF selTxt seaLoc))
  136.          (setq seaLoc (+ seaLoc (strlen strinR)))
  137.          (setq count (1+ count))
  138.          )
  139.        (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) selTxt)
  140.        )
  141.      )
  142.     ((mlml (list case) (list "N" "NO"))
  143.      ; Compare using (vl-string-search (strcase strinF) (strcase input)), modify using (vl-string-subst) within a while loop
  144.      (foreach selVar selSet
  145.        (setq selTxt (nth 0 selVar))
  146.        (setq seaLoc 0)
  147.        (while (setq seaLoc (vl-string-search (strcase strinF) (strcase selTxt) seaLoc))
  148.          (setq selTxt (strcat (substr selTxt 1 seaLoc) strinR (substr selTxt (+ 1 seaLoc (strlen strinF)))))
  149.          (setq seaLoc (+ seaLoc (strlen strinR)))
  150.          (setq count (1+ count))
  151.          )
  152.        (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) selTxt)
  153.        )
  154.      )
  155.     )
  156.       (if (= count 0) (setq error "\nNo occurances found.") (setq error (strcat (itoa count) " occurances modified.")))
  157.       (setq goTo
  158.       )
  159.      ((= goTo
  160.       (if error (princ error))
  161.       (setq goWhile nil)
  162.       )
  163.      )
  164.    )
  165. (princ)
  166. )
  167. (defun mlml(inSMLChar inSMLStri / returnVarMS toCheck chkWith)
  168. (setq returnVarMS nil)
  169. (if (and (= (type inSMLChar) 'LIST)
  170.       (= (type inSMLStri) 'LIST)
  171.       )
  172.    (progn
  173.      (foreach toCheck inSMLStri
  174.    (foreach chkWith inSMLChar
  175.      (if (eq toCheck chkWith) (setq returnVarMS T))
  176.      )
  177.    )
  178.      );/progn
  179.    )
  180. returnVarMS
  181. ); Checks a list to see if a member of that list is the same as a member of another list. Returns T or nil
  182. (defun extTxtPt(ssList / subVar getEnt entTyp entTxt entPnt entLay entHgt grp66 entAtt getEntAtt entAttTyp uniLst)
  183. (setq uniLst nil)
  184. (setq subVar 0)
  185. (if ssList
  186. (repeat (sslength ssList)
  187.    (setq getEnt (entget (cadr (car (ssnamex ssList subVar)))))
  188.    (setq entTyp (cdr (assoc 0 getEnt)))
  189.    (cond
  190.      ((or (= entTyp "TEXT") (= entTyp "MTEXT"))
  191.       (setq entTxt (cdr (assoc 1 getEnt)))
  192.       (setq entPnt (cdr (assoc 10 getEnt)))
  193.       (setq entHgt (cdr (assoc 40 getEnt)))
  194.       (setq entLay (cdr (assoc 410 getEnt)))
  195.       (setq entNam (cdr (assoc -1 getEnt)))
  196.       (setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
  197.       )
  198.      ((= entTyp "INSERT")
  199.       (setq grp66 (assoc 66 getEnt))
  200.       (if grp66
  201.     (progn
  202.       (setq entAtt (entnext (cdr (assoc -1 getEnt))))
  203.           (setq getEntAtt (entget entAtt))
  204.           (setq entAttTyp (cdr (assoc 0 getEntAtt)))
  205.       )
  206.     )
  207.       (while (= entAttTyp "ATTRIB")
  208.     (setq entTxt (cdr (assoc 1 getEntAtt)))
  209.     (setq entPnt (cdr (assoc 10 getEntAtt)))
  210.         (setq entHgt (cdr (assoc 40 getEntAtt)))
  211.     (setq entLay (cdr (assoc 410 getEntAtt)))
  212.     (setq entNam (cdr (assoc -1 getEntAtt)))
  213.    
  214.     (setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
  215.     ; Get next entity.
  216.     (setq entAtt (entnext (cdr (assoc -1 getEntAtt))))
  217.     ; Get ent and ent type
  218.     (setq getEntAtt (entget entAtt))
  219.     (setq entAttTyp (cdr (assoc 0 getEntAtt)))
  220.     )
  221.       )
  222.      (t
  223.       )
  224.      )
  225.    (setq subVar (1+ subVar))
  226.    )
  227.    )
  228. uniLst
  229. ); Return list of all text-based objects (Text, MText, Attribute) in the current drawing
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:27:43 | 显示全部楼层
  1. ;;;-------------------------------------------------------------------
  2. ;; This function is freeware courtesy of the author's of "Inside AutoLisp"
  3. ;; for rel. 10 published by New Riders Publications.  This credit must
  4. ;; accompany all copies of this function.
  5. ;;* UKWORD User key word. DEF, if any, must match one of the KWD strings
  6. ;;* BIT (1 for no null, 0 for none) and KWD key word ("" for none) are same as
  7. ;;* for INITGET. MSG is the prompt string, to which a default string is added
  8. ;;* as <DEF> (nil or "" for none), and a : is added.
  9. ;;*
  10. (defun UKWORD (bit kwd msg def / inp)
  11. (if (and def (/= def ""))
  12.    (setq msg (strcat "\n" msg " <" def "> : ")
  13.          bit (* 2 (fix (/ bit 2)))
  14.          )                             ;setq
  15.    )                                   ;if
  16. (initget bit kwd)
  17. (setq inp (getkword msg))
  18. (if inp inp def)
  19. )                                     ;defun

 
示例:默认情况下,只需[ENTER]=“FIND”
  1. (UKWORD 0 "Find Replace Quit Case"
  2.        "\nSelect option [Find/Replace/Quit/Case]: "
  3. "FIND")
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 20:32:18 | 显示全部楼层
 
你好,韩。
 
原谅我的无知。
 
不太明白。附加的lisp是独立的还是合并到查找文本lisp中?
 
如果要加入公司,我应该在哪一部分和哪里插入?
 
谢谢
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:39:54 | 显示全部楼层
这是TFIND。lsp代码是别人写的,所以我尊重他之前在“通知->收件箱”中回复帖子#3的工作
也许你没有注意到?
 
;你试着编辑自己,这样你也可以学习
  1. ; Obtain desired option from user
  2. (while (not (mlml (list (setq searep (strcase (getstring nil "\nSelect option [Find/Replace/Quit/Case]: "))))
  3. (list "F" "FIND" "R" "REPLACE" "Q" "QUIT" "C" "CASE")
  4. ))
  5. )

到这个
  1. (setq searep (strcase
  2. (UKWORD 0 "Find Replace Quit Case"
  3.        "\nSelect option [Find/Replace/Quit/Case]: "
  4. "FIND")
  5. ))
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 20:44:51 | 显示全部楼层
 
 
哎呀。我不知道有你的下午。
 
理解。我明天会试试。谢谢
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:53:17 | 显示全部楼层
没关系
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 20:55:46 | 显示全部楼层
FWIW-
 
我个人使用过,并且通常是李的批量查找和替换文本例程的粉丝。
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 20:59:15 | 显示全部楼层
 
 
先生,我同意你的看法,毫无疑问,李的表演很精彩,但有时许多人仍在寻找适合自己需要的替代品
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-5 21:06:16 | 显示全部楼层
 
别担心;这就是为什么我以“为了它的价值”(又名FWIW)开始我的评论。
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 21:10:37 | 显示全部楼层
 
嗨,黑匣子。我以前也遇到过李的Lisp程序,我试过,因为时间很短,因为它涉及一个对话框,它并没有提供我需要的快速文本搜索(类似于Firefox浏览器搜索栏,(说真的,应该有一个)。
 
因此,目前,马克·梅西尔(Mark Mercier)的作品是最快的,最符合我的需要,即缩放到文本(特别是我正在快速连续搜索的门标签,例如,1-10…缩放…….1-45…缩放…….4-32…缩放……等等)。
虽然我仍然需要找到整个单词,而不是像通配符一样搜索。
(当我输入1-2时,它将循环到1-21、1-22、1-23、1-24,然后最后是1-2。)
 
所以基本上我无法打开那个或任何使用搜索框的lisp,输入提供的spae,移动鼠标单击enter,等待对话框关闭并缩放到门标签,然后重复一遍。
 
基本上,在这种情况下,命令行仍然工作得更快。
 
尽管如此,我愿意接受建议。只要比我现在做的更快
 
我很想补充一点,我也用了一些李的Lisp程序,简直太神奇了。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 09:23 , Processed in 0.540988 second(s), 72 queries .

© 2020-2025 乐筑天下

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