Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FIND TEXT LSP

36 REPLIES 36
SOLVED
Reply
Message 1 of 37
jlaidle1
6733 Views, 36 Replies

FIND TEXT LSP

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.

36 REPLIES 36
Message 2 of 37
CodeDing
in reply to: jlaidle1

@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

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 37
jlaidle1
in reply to: CodeDing

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.

Message 4 of 37
hak_vz
in reply to: jlaidle1


@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.
Message 5 of 37
jlaidle1
in reply to: hak_vz

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
in reply to: jlaidle1

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.

Message 7 of 37
jlaidle1
in reply to: pendean

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.

Message 8 of 37
devitg
in reply to: jlaidle1

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

 

Message 9 of 37
jlaidle1
in reply to: devitg

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.

Message 10 of 37
jlaidle1
in reply to: devitg

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.

Message 11 of 37
pendean
in reply to: jlaidle1

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?

Message 12 of 37
jlaidle1
in reply to: pendean

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.

Message 13 of 37
pendean
in reply to: jlaidle1

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

Message 14 of 37
jlaidle1
in reply to: pendean

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.

Message 15 of 37
john.uhden
in reply to: jlaidle1

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

Message 16 of 37
ronjonp
in reply to: john.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.

Message 17 of 37
john.uhden
in reply to: ronjonp

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

John F. Uhden

Message 18 of 37
Sea-Haven
in reply to: john.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

 

screenshot148.png

Message 19 of 37
john.uhden
in reply to: ronjonp

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

Message 20 of 37
ronjonp
in reply to: john.uhden

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

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost