FIND TEXT LSP

FIND TEXT LSP

jlaidle1
Advocate Advocate
12,002 Views
36 Replies
Message 1 of 37

FIND TEXT LSP

jlaidle1
Advocate
Advocate

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.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Accepted solutions (2)
12,003 Views
36 Replies
Replies (36)
Message 2 of 37

CodeDing
Mentor
Mentor

@jlaidle1 ,

 

This topic has been asked and answered in quite some detail here:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pre-defined-find-amp-replace-lisp/td...

 

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

0 Likes
Message 3 of 37

jlaidle1
Advocate
Advocate

Yeah, I saw that thread.  I just need a 'find' option, no need for a replace.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 4 of 37

hak_vz
Advisor
Advisor

@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

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 37

jlaidle1
Advocate
Advocate

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.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 6 of 37

pendean
Community Legend
Community Legend
Forgive me, but "larger files" just means more content to search through, which means longer times to process the command. What changes are you expecting a LISP to do any faster?

Or are you just wanting to turn off some FIND command features or perhaps just need to pre-select a limited area of search that FIND can already do?

Explain. Elaborate.

0 Likes
Message 7 of 37

jlaidle1
Advocate
Advocate

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'.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 8 of 37

devitg
Advisor
Advisor

Please upload your sample.dwg , qeep out all but text. 

 

0 Likes
Message 9 of 37

jlaidle1
Advocate
Advocate

I cannot upload any of our drawings.  But any test drawing with text will work.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 10 of 37

jlaidle1
Advocate
Advocate

I just created the attached sample file with only text objects, if that helps.

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 11 of 37

pendean
Community Legend
Community Legend

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?

0 Likes
Message 12 of 37

jlaidle1
Advocate
Advocate

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.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 13 of 37

pendean
Community Legend
Community Legend
let's start over: NONE of us see a slowness or a problem with FIND command in any of our files, or your file.

So please show us a video of your usage of your command in one of your files that exhibits a problem you can repeat than most of us here either cannot or don't see what you see.

I recommend you use Autodesk's Screencast as it records the commands to launch and show us what you are doing, here is the link https://knowledge.autodesk.com/search-result/caas/simplecontent/content/download-autodesk-screencast...

0 Likes
Message 14 of 37

jlaidle1
Advocate
Advocate

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.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 15 of 37

john.uhden
Mentor
Mentor

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

0 Likes
Message 16 of 37

ronjonp
Mentor
Mentor
(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.

Message 17 of 37

john.uhden
Mentor
Mentor
A very good point about which I had forgotten.
But I think a couple of

John F. Uhden

0 Likes
Message 18 of 37

Sea-Haven
Mentor
Mentor

It may be worth doing a ask Model, 1 layout, All etc and then yes loop through the (410's could add pick layout

 

screenshot148.png

0 Likes
Message 19 of 37

john.uhden
Mentor
Mentor

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

0 Likes
Message 20 of 37

ronjonp
Mentor
Mentor

@john.uhden  Curious ... why do you include this?

(command "_.expert" (getvar "expert")) ;; dummy command
0 Likes