寻求进一步帮助
hanhphuc已经帮我修改了lisp,将FIND作为默认选择。
第二条我对此仍然迷茫。
希望有人能为lisp提供一些建议,让它能够搜索整个单词。并且只允许在指示*时进行通配符搜索。
谢谢
这是将“查找”作为默认选择的代码
- ;-============-;
- ;- Text Find -;
- ;- *~* -;
- ; Written by -;
- ; Mark Mercier ;
- ; 05-06-09 ;
- ;-============-;
- ; Improvements:
- ; Text within blocks
- ; Improved selection set.. maybe do away with the whole "list" thing and go straight VLA
- http://www.cadtutor.net/forum/showthread.php?35933-The-Best-Text-Find-And-Replace-LISP-Ever...
- (defun c:tfind( / *object* )
- (or *object* (setq *object* (vlax-get-acad-object)))
- (tfindfun nil nil 0)
- )
- (defun-q tfindfun(inputF inputR caseSn / goto goWhile strinF strinR selSet selTxt searep case count error)
- ; 01 Create selection set. GOTO 02 if success, or GOTO 08 if fail
- ; 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
- ; 03 Display menus and obtain data from user. If Search, GOTO 04. If Replace, GOTO 05
- ; 04 Search option selected. Prompt user for single search term. GOTO 06
- ; 05 Replace option selected. Prompt user for search term and replace term. GOTO 07
- ; 06 One string has been passed. Assume automatic search. Run same as current (tfind). GOTO FINISH
- ; 07 Two strings have been passed. Assume automatic replace. Pass both strings to (replace) function. GOTO FINISH
- ; 08 FINISH. Return errors if needed. End loop and program.
- (vl-load-com)
- (setq goTo 1)
- (setq goWhile 1)
- (setq count 0)
- (if (not (mlml (list caseSn) (list 0 1))) (progn (setq goWhile nil) (princ "\nCase selection not recognized.")))
- (if (= caseSn 0) (setq case "N") (setq case "Y"))
- (while goWhile
- (cond
- ((= goTo 1)
- (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>")))))
- (if selSet (setq goTo 2) (setq error "\nSelection set not found." goTo )
- )
- ((= goTo 2)
- ; Check input, pass to whatever.
- (cond
- ((and (= inputF nil) (= inputR nil))
- (setq goTo 3)
- )
- ((and (= (type inputF) 'STR) (= inputR nil))
- (setq strinF inputF)
- (setq goTo 6)
- )
- ((and (= (type inputF) 'STR) (= (type inputR) 'STR))
- (setq strinF inputF)
- (setq strinR inputR)
- (setq goTo 7)
- )
- (t
- (setq error "\nPassed arguments are not accepted.")
- (setq goTo
- )
- )
- )
- ((= goTo 3)
- ; Obtain desired option from user
- ;;; (while (not (mlml (list (setq searep (strcase (getstring nil "\nSelect option [Find/Replace/Quit/Case]: "))))
- ;;; (list "F" "FIND" "R" "REPLACE" "Q" "QUIT" "C" "CASE")
- ;;; ))
- ;;; )
-
- ;;;v1.1:
- (setq searep (strcase
- (UKWORD 0 "Find Replace Quit Case"
- "\nSelect option [Find/Replace/Quit/Case]: "
- "FIND")
- ))
-
- (cond
- ((mlml (list searep) (list "F" "FIND"))
- (setq goTo 4)
- )
- ((mlml (list searep) (list "R" "REPLACE"))
- (setq goTo 5)
- )
- ((mlml (list searep) (list "Q" "QUIT"))
- (setq goTo
- )
- ((mlml (list searep) (list "C" "CASE"))
- (while (not (mlml (list (setq case (strcase (getstring nil "\nCase sensitive? [Yes/No]: "))))
- (list "Y" "YES" "N" "NO")
- ))
- )
- )
- )
- )
- ((= goTo 4)
- ; Obtain search string from user, set to strinF
- (while (eq "" (setq strinF (getstring T "\nEnter search term: "))))
- (setq goTo 6)
- )
- ((= goTo 5)
- ; Obtain search string and replace string from user, set to strinF and strinR respectively
- (while (eq "" (setq strinF (getstring T "\nEnter find term: "))))
- (while (eq "" (setq strinR (getstring T "\nEnter replace term: "))))
- (setq goTo 7)
- )
- ((= goTo 6)
- ; Search drawing for strinF
- (cond
- ((mlml (list case) (list "Y" "YES"))
- ; Compare using (vl-string-search strinF input), view selection
- ; use "while" to get all search occurances
- (foreach selVar selSet
- (if
- ;;; (vl-string-search strinF (nth 0 selVar))
- (eq strinF (car selVar)) ;v1.1
- (progn
- (setq count (1+ count))
- (if (/= (getvar "ctab") (caddr selVar)) (command "ctab" (caddr selVar)))
|