The FIND and REPLACE command in AutoCAD is good, but not for our large drawing files. What I need is a simple 'find' command (lsp) that will search for a single text value.
The FIND and REPLACE command takes too long for our users to close, because it seems to be completing the search.
The more objects in the drawing, the longer it takes to close.
Any help would be greatly appreciated.
Solved! Go to Solution.
Solved by ronjonp. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
This topic has been asked and answered in quite some detail here:
Perhaps you could read through this thread first and see if it gets you on the right track. It explains the details and how you should approach this depending on if you're always searching for one item or if the search term will change.
Let us know if that helps.
Best,
~DD
Yeah, I saw that thread. I just need a 'find' option, no need for a replace.
@jlaidle1 wrote:Yeah, I saw that thread. I just need a 'find' option, no need for a replace.
Do you mean that find has to mimic "FIND" comand and to zoom at text (mtext) with particular content, or to select all text to be changed (altered color, move ....) into a selection set?
Miljenko Hatlak
If it an be just like the FIND command and step thru each text location, that is what is needed.
The best solution, would to have the AutoCAD FIND dialog work better with larger files. But I don't see that happening soon.
The change is, it takes a LONG time to close the 'Find and Replace' dialog. When selecting 'done', it would be nice that the dialog just closes. So, the LSP would stop searching after the user selects 'cancel'.
I cannot upload any of our drawings. But any test drawing with text will work.
I just created the attached sample file with only text objects, if that helps.
This posted file of your is a problem for you? It closed immediately here, no issues. R2019.1.2 here. See attached.
What's the add-on (cimfdataholder) you have that shows up in your file?
Are you perhaps talking about having to pop-ups to deal with to OK out of instead of one?
cimfdataholder is for 'FactoryCAD'. I'm not having issues with the DWG, its just a drawing I just created. You can use a test file that you created, that should work.
As stated, the slowness in closing the find dialog is with our HUGE files.
The smaller files don't have the issue, but most of our layouts are pretty big.
Hi, John.
Here is a very simplistic offering to just grip all text in the current layout that contains a given text string.
Note that case IS sensitive.
(defun C:SimpleFind ( / *error* vars vals ss str) ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;* * ;* SimpleFind.LSP by John F. Uhden * ;* 2 Village Road * ;* Sea Girt, NJ 08750 * ;* * ;* * * * * * * * * * * * Do not delete this heading! * * * * * * * * * * * * ; Program performs a simple search for text in the current layout ; v1.0 (01-24-2020) made for John Laidler (gc) (prompt "\nSimpleFind v1.0 (c)2020, John F. Uhden") (defun *error* (error) (mapcar 'setvar vars vals) (vla-endundomark *doc*) (cond (not error) ((wcmatch (strcase error) "*CANCEL*,*QUIT*") (vl-exit-with-error "\r ") ) (1 (vl-exit-with-error (strcat "\r*ERROR*: " error))) ) (princ) ) ;;------------------------------------------ ;; Intitialze drawing and program variables: ;; (setq *acad* (vlax-get-acad-object)) (setq *doc* (vlax-get *acad* 'ActiveDocument)) (vla-endundomark *doc*) (vla-startundomark *doc*) (setq vars '("cmdecho" "highlight")) (setq vals (mapcar 'getvar vars)) (mapcar 'setvar vars '(0 1)) (command "_.expert" (getvar "expert")) ;; dummy command (and (setq str (getstring T "\nEnter string to find: ")) (setq str (strcat "*" str "*")) (setq ss (ssget "X" (list '(0 . "*TEXT")(cons 1 str)(cons 410 (getvar "ctab"))))) (princ (strcat "\nFound " (itoa (sslength ss)) " matching text entities.")) (sssetfirst nil ss) ) (*error* nil) ) (defun c:SFind ()(c:SimpleFind))
John F. Uhden
(setq ss (ssget "X" (list '(0 . "*TEXT")(cons 1 str)(cons 410 (getvar "ctab")))))
@john.uhden FYI .. this filter will fail on long MTEXT strings since the text is stored in multiple 3 codes.
John F. Uhden
It may be worth doing a ask Model, 1 layout, All etc and then yes loop through the (410's could add pick layout
This version should handle long text strings, though it is likely to be slower.
(defun C:SimpleFind ( / *error* vars vals ss str i obj found) ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;* * ;* SimpleFind.LSP by John F. Uhden * ;* 2 Village Road * ;* Sea Girt, NJ 08750 * ;* * ;* * * * * * * * * * * * Do not delete this heading! * * * * * * * * * * * * ; Program performs a simple search for text in the current layout ; v1.0 (01-24-2020) made for John Laidler ; v1.1 (01-27-2020) revised to handle long text strings (gc) (prompt "\nSimpleFind v1.1 (c)2020, John F. Uhden") (defun *error* (error) (mapcar 'setvar vars vals) (vla-endundomark *doc*) (cond (not error) ((wcmatch (strcase error) "*CANCEL*,*QUIT*") (vl-exit-with-error "\r ") ) (1 (vl-exit-with-error (strcat "\r*ERROR*: " error))) ) (princ) ) ;;------------------------------------------ ;; Intitialze drawing and program variables: ;; (setq *acad* (vlax-get-acad-object)) (setq *doc* (vlax-get *acad* 'ActiveDocument)) (vla-endundomark *doc*) (vla-startundomark *doc*) (setq vars '("cmdecho" "highlight")) (setq vals (mapcar 'getvar vars)) (mapcar 'setvar vars '(0 1)) (command "_.expert" (getvar "expert")) ;; dummy command (and (setq str (getstring T "\nEnter string to find (case IS sensitive): ")) (setq str (strcat "*" str "*")) (setq ss (ssget "X" (list '(0 . "*TEXT")(cons 410 (getvar "ctab"))))) (setq found (ssadd)) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i))) obj (vlax-ename-vla-object e) ) (if (wcmatch (vlax-get obj 'TextString) str) (ssadd e found) ) ) (princ (strcat "\nFound " (itoa (sslength found)) " matching text entities.")) (sssetfirst nil found) ) (*error* nil) ) (defun c:SFind ()(c:SimpleFind))
John F. Uhden
@john.uhden Curious ... why do you include this?
(command "_.expert" (getvar "expert")) ;; dummy command