Jump to content

Batch Find and Replace


afritz0108

Recommended Posts

Hello all,

im looking for a script or lisp that can change text inside a block on multiple drawings. 
I have no experience with Autocad Lisp.

I’ve attached the block. Is there a way to change the text to whatever I need?

Block.dwg

Link to comment
Share on other sites

I use this for find and replace:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-and-replace-text/td-p/5649883

 

Does attribute text and non attribute text (think Lees only does attribute text? Though it is very quick and very good to change attributes as a batch on lots of drawings.). I'd use it with Lees sriptwriter function.

 

If I am changing only attributes - use Lees

Link to comment
Share on other sites

Steven 

What would I need to change on the code for it to work? Also how does it work on multiple drawings?

Currently it says error too few arguments

Link to comment
Share on other sites

You'll need to send the correct inputs to this LISP to make it work, something like this:

 

(defun c:txtFindReplace( / old_text new_text)
  (setq old_text (getstring T "OLD Text to replace (replace in this model/paper space and text case as entered): "))
  (setq new_text (getstring T "NEW Text: "))
  (c:FindReplaceAll old_text new_text)
  (princ)
)

 

All you really need is this line:

 

(c:FindReplaceAll old_text new_text)

 

I think this works with Lees ScriptWriter and also Scriptwriterpro:

 

_.Open *file* FindReplaceAll "Old Text" "New Text" _.Saveas *file* _.Close

 

something like that

Link to comment
Share on other sites

Yes, so try this to see it work, open a drawing or start a new drawing and insert some text, go old school and "Hello world", load up the LISP from my AutoDesk link an also the c:textfindreplace LISP

 

Now try this and noting the " " either side of the 2 text strings

 

(c:FindReplaceAll "Hello World" "Goodbye World")

 

This should change the text. You do the same, insert or create a block and again insert a text into the block and also an attribute. Put text to be maybe "Hello World", and change the attribute to be "Goodbye World".. you should have a block and a text, then run the line again, perhaps this time: 

 

(c:FindReplaceAll "Goodbye World" "Hello World")

 

and with luck all 3 texts will all say Hello World. Try again without the capitals and and since the LISP is case sensitive nothing will change.

Link to comment
Share on other sites

Try this subtle change saves typing one find variable. You can copy parts of the text from command line and use in new text the T supports spaces in new string.

 

; Findreplaceall By Terry Cad 2006

(defun c:txtFindReplace( / strold strnew)
(if (not Findreplaceall)(load "findreplaceall.lsp"))
  (while (setq ent (car (nentsel "\nPick source text Enter to exit ")))
    (setq obj (vlax-ename->vla-object ent))
    (setq strold (vlax-get obj 'textstring))
    (setq strnew (getstring (strcat "\nReplace " strold " with ? ") T))
    (c:FindReplaceAll strold strnew)
  )
(princ)
)
(c:txtFindReplace)

 

findreplaceall.lsp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...