乐筑天下

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

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

[复制链接]

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 21:15:27 | 显示全部楼层
 
对于整个单词:跳过这些vl字符串搜索,
ie:使字符串F和选择字符串足够匹配。
*项目经理*
 
编辑:如果选择全字匹配,请注意它是否适用于某些格式的多行文字?
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

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

铜币
240
发表于 2022-7-5 21:20:25 | 显示全部楼层
寻求进一步帮助
 
hanhphuc已经帮我修改了lisp,将FIND作为默认选择。
 
第二条我对此仍然迷茫。
 
希望有人能为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. http://www.cadtutor.net/forum/showthread.php?35933-The-Best-Text-Find-And-Replace-LISP-Ever...
  12. (defun c:tfind( / *object* )
  13. (or *object*   (setq *object* (vlax-get-acad-object)))
  14. (tfindfun nil nil 0)
  15. )
  16. (defun-q tfindfun(inputF inputR caseSn / goto goWhile strinF strinR selSet selTxt searep case count error)
  17. ; 01 Create selection set. GOTO 02 if success, or GOTO 08 if fail
  18. ; 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
  19. ; 03 Display menus and obtain data from user. If Search, GOTO 04. If Replace, GOTO 05
  20. ; 04 Search option selected. Prompt user for single search term. GOTO 06
  21. ; 05 Replace option selected. Prompt user for search term and replace term. GOTO 07
  22. ; 06 One string has been passed. Assume automatic search. Run same as current (tfind). GOTO FINISH
  23. ; 07 Two strings have been passed. Assume automatic replace. Pass both strings to (replace) function. GOTO FINISH
  24. ; 08 FINISH. Return errors if needed. End loop and program.
  25. (vl-load-com)
  26. (setq goTo 1)
  27. (setq goWhile 1)
  28. (setq count 0)
  29. (if (not (mlml (list caseSn) (list 0 1))) (progn (setq goWhile nil) (princ "\nCase selection not recognized.")))
  30. (if (= caseSn 0) (setq case "N") (setq case "Y"))
  31. (while goWhile
  32.    (cond
  33.      ((= goTo 1)
  34.       (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>")))))
  35.       (if selSet (setq goTo 2) (setq error "\nSelection set not found." goTo )
  36.       )
  37.      ((= goTo 2)
  38.       ; Check input, pass to whatever.
  39.       (cond
  40.     ((and (= inputF nil) (= inputR nil))
  41.      (setq goTo 3)
  42.      )
  43.     ((and (= (type inputF) 'STR) (= inputR nil))
  44.      (setq strinF inputF)
  45.      (setq goTo 6)
  46.      )
  47.     ((and (= (type inputF) 'STR) (= (type inputR) 'STR))
  48.      (setq strinF inputF)
  49.      (setq strinR inputR)
  50.      (setq goTo 7)
  51.      )
  52.     (t
  53.      (setq error "\nPassed arguments are not accepted.")
  54.      (setq goTo
  55.      )
  56.     )
  57.       )
  58.      ((= goTo 3)
  59.       ; Obtain desired option from user
  60. ;;;       (while (not (mlml (list (setq searep (strcase (getstring nil "\nSelect option [Find/Replace/Quit/Case]: "))))
  61. ;;;                 (list "F" "FIND" "R" "REPLACE" "Q" "QUIT" "C" "CASE")
  62. ;;;                 ))
  63. ;;;     )
  64.       
  65. ;;;v1.1:
  66. (setq searep (strcase
  67. (UKWORD 0 "Find Replace Quit Case"
  68.        "\nSelect option [Find/Replace/Quit/Case]: "
  69.    "FIND")
  70. ))
  71.       
  72.       (cond
  73.     ((mlml (list searep) (list "F" "FIND"))
  74.      (setq goTo 4)
  75.      )
  76.     ((mlml (list searep) (list "R" "REPLACE"))
  77.      (setq goTo 5)
  78.      )
  79.     ((mlml (list searep) (list "Q" "QUIT"))
  80.      (setq goTo
  81.      )
  82.     ((mlml (list searep) (list "C" "CASE"))
  83.      (while (not (mlml (list (setq case (strcase (getstring nil "\nCase sensitive? [Yes/No]: "))))
  84.                    (list "Y" "YES" "N" "NO")
  85.                    ))
  86.        )
  87.      )
  88.     )
  89.       )
  90.      ((= goTo 4)
  91.       ; Obtain search string from user, set to strinF
  92.       (while (eq "" (setq strinF (getstring T "\nEnter search term: "))))
  93.       (setq goTo 6)
  94.       )
  95.      ((= goTo 5)
  96.       ; Obtain search string and replace string from user, set to strinF and strinR respectively
  97.       (while (eq "" (setq strinF (getstring T "\nEnter find term: "))))
  98.       (while (eq "" (setq strinR (getstring T "\nEnter replace term: "))))
  99.       (setq goTo 7)
  100.       )
  101.      ((= goTo 6)
  102.       ; Search drawing for strinF
  103.       (cond
  104.     ((mlml (list case) (list "Y" "YES"))
  105.      ; Compare using (vl-string-search strinF input), view selection
  106.      ; use "while" to get all search occurances
  107.      (foreach selVar selSet
  108.        (if
  109. ;;;      (vl-string-search strinF (nth 0 selVar))
  110.     (eq strinF (car selVar)) ;v1.1
  111.          (progn
  112.        (setq count (1+ count))
  113.        (if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
  114. ;;;        (command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar))); v1.1:removed
  115.    (vla-ZoomCenter *object* (vlax-3d-point (trans (cadr selVar) 0 1)) (* 32 (nth 3 selVar)))
  116.        (getstring "\nPress 'Enter' to continue: ")
  117.        )
  118.          )
  119.        )
  120.      )
  121.     ((mlml (list case) (list "N" "NO"))
  122.      ; Compare using (vl-string-search (strcase strinF) (strcase input)), view selection
  123.      ; use "while" to get all search occurances
  124.      (foreach selVar selSet
  125.        (if
  126. ;;;      (vl-string-search (strcase strinF) (strcase (nth 0 selVar))) ;
  127.       (eq (strcase strinF) (strcase (nth 0 selVar))) ;v1.1
  128.          (progn
  129.        (setq count (1+ count))
  130.        (if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
  131. ;;;        (command "zoom" "c" (trans (cadr selVar) 0 1) (* 32 (nth 3 selVar))) ; v1.1:removed
  132.    (vla-ZoomCenter *object* (vlax-3d-point (trans (cadr selVar) 0 1)) (* 32 (nth 3 selVar)))
  133.        (getstring "\nPress 'Enter' to continue: ")
  134.        )
  135.          )
  136.        )
  137.      )
  138.     )
  139.       (if (= count 0) (setq error "\nNo matches found.") (setq error (strcat (itoa count) " matches found.")))
  140.       (setq goTo
  141.       )
  142.      ((= goTo 7)
  143.       ; Replace strinF with strinR
  144.       (cond
  145.     ((mlml (list case) (list "Y" "YES"))
  146.      ; Compare using (vl-search-string strinF input), modify using (vl-string-subst) within a while loop
  147.      (foreach selVar selSet
  148. ;;;        (setq selTxt (nth 0 selVar))
  149. ;;;        (setq seaLoc 0)
  150. ;;;        (while
  151. ;;;      (setq seaLoc (vl-string-search strinF selTxt seaLoc))
  152. ;;;          (setq selTxt (vl-string-subst strinR strinF selTxt seaLoc))
  153. ;;;          (setq seaLoc (+ seaLoc (strlen strinR)))
  154. ;;;          (setq count (1+ count))
  155. ;;;          )
  156. ;;;        (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) selTxt)
  157.    (if
  158.    (= (car selVar) strinF)  
  159.    (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) strinR ))
  160.        )
  161.      )
  162.     ((mlml (list case) (list "N" "NO"))
  163.      ; Compare using (vl-string-search (strcase strinF) (strcase input)), modify using (vl-string-subst) within a while loop
  164.      (foreach selVar selSet
  165.    
  166. ;;;        (setq selTxt (nth 0 selVar))
  167. ;;;        (setq seaLoc 0)
  168. ;;;        (while
  169. ;;;      (setq seaLoc (vl-string-search (strcase strinF) (strcase selTxt) seaLoc))
  170. ;;;      
  171. ;;;          (setq selTxt (strcat (substr selTxt 1 seaLoc) strinR (substr selTxt (+ 1 seaLoc (strlen strinF)))))
  172. ;;;          (setq seaLoc (+ seaLoc (strlen strinR)))
  173. ;;;          (setq count (1+ count))
  174. ;;;          )
  175. ;;;        (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) selTxt)
  176.    
  177.    (if(=(strcase (car selVar))(strcase strinF))
  178.    (vla-put-TextString (vlax-ename->vla-object (nth 4 selVar)) strinR ))
  179.    
  180.        )
  181.      )
  182.     )
  183.       (if (= count 0) (setq error "\nNo occurances found.") (setq error (strcat (itoa count) " occurances modified.")))
  184.       (setq goTo
  185.       )
  186.      ((= goTo
  187.       (if error (princ error))
  188.       (setq goWhile nil)
  189.       )
  190.      )
  191.    )
  192. (princ)
  193. )
  194. (defun mlml(inSMLChar inSMLStri / returnVarMS toCheck chkWith)
  195. (setq returnVarMS nil)
  196. (if (and (= (type inSMLChar) 'LIST)
  197.       (= (type inSMLStri) 'LIST)
  198.       )
  199.    (progn
  200.      (foreach toCheck inSMLStri
  201.    (foreach chkWith inSMLChar
  202.      (if (eq toCheck chkWith) (setq returnVarMS T))
  203.      )
  204.    )
  205.      );/progn
  206.    )
  207. returnVarMS
  208. ); Checks a list to see if a member of that list is the same as a member of another list. Returns T or nil
  209. (defun extTxtPt(ssList / subVar getEnt entTyp entTxt entPnt entLay entHgt grp66 entAtt getEntAtt entAttTyp uniLst)
  210. (setq uniLst nil)
  211. (setq subVar 0)
  212. (if ssList
  213. (repeat (sslength ssList)
  214.    (setq getEnt (entget (cadr (car (ssnamex ssList subVar)))))
  215.    (setq entTyp (cdr (assoc 0 getEnt)))
  216.    (cond
  217.      ((or (= entTyp "TEXT") (= entTyp "MTEXT"))
  218.       (setq entTxt (cdr (assoc 1 getEnt)))
  219.       (setq entPnt (cdr (assoc 10 getEnt)))
  220.       (setq entHgt (cdr (assoc 40 getEnt)))
  221.       (setq entLay (cdr (assoc 410 getEnt)))
  222.       (setq entNam (cdr (assoc -1 getEnt)))
  223.       (setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
  224.       )
  225.      ((= entTyp "INSERT")
  226.       (setq grp66 (assoc 66 getEnt))
  227.       (if grp66
  228.     (progn
  229.       (setq entAtt (entnext (cdr (assoc -1 getEnt))))
  230.           (setq getEntAtt (entget entAtt))
  231.           (setq entAttTyp (cdr (assoc 0 getEntAtt)))
  232.       )
  233.     )
  234.       (while (= entAttTyp "ATTRIB")
  235.     (setq entTxt (cdr (assoc 1 getEntAtt)))
  236.     (setq entPnt (cdr (assoc 10 getEntAtt)))
  237.         (setq entHgt (cdr (assoc 40 getEntAtt)))
  238.     (setq entLay (cdr (assoc 410 getEntAtt)))
  239.     (setq entNam (cdr (assoc -1 getEntAtt)))
  240.    
  241.     (setq uniLst (append uniLst (list (list entTxt entPnt entLay entHgt entNam))))
  242.     ; Get next entity.
  243.     (setq entAtt (entnext (cdr (assoc -1 getEntAtt))))
  244.     ; Get ent and ent type
  245.     (setq getEntAtt (entget entAtt))
  246.     (setq entAttTyp (cdr (assoc 0 getEntAtt)))
  247.     )
  248.       )
  249.      (t
  250.       )
  251.      )
  252.    (setq subVar (1+ subVar))
  253.    )
  254.    )
  255. uniLst
  256. ); Return list of all text-based objects (Text, MText, Attribute) in the current drawing
  257. ;("1.x11" (1307.62 1349.77 0.0) "Model" 51.5188 <Entity name: 7efa8af0>)
  258. ;;;-------------------------------------------------------------------
  259. ;; This function is freeware courtesy of the author's of "Inside AutoLisp"
  260. ;; for rel. 10 published by New Riders Publications.  This credit must
  261. ;; accompany all copies of this function.
  262. ;;* UKWORD User key word. DEF, if any, must match one of the KWD strings
  263. ;;* BIT (1 for no null, 0 for none) and KWD key word ("" for none) are same as
  264. ;;* for INITGET. MSG is the prompt string, to which a default string is added
  265. ;;* as <DEF> (nil or "" for none), and a : is added.
  266. ;;*
  267. (defun UKWORD (bit kwd msg def / inp)
  268. (if (and def (/= def ""))
  269.    (setq msg (strcat "\n" msg " <" def "> : ")
  270.          bit (* 2 (fix (/ bit 2)))
  271.          )                             ;setq
  272.    )                                   ;if
  273. (initget bit kwd)
  274. (setq inp (getkword msg))
  275. (if inp inp def)
  276. )           
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 09:17 , Processed in 1.010786 second(s), 54 queries .

© 2020-2025 乐筑天下

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