Batch Find and Replace

Batch Find and Replace

bmanalanDX6VM
Participant Participant
1,080 Views
18 Replies
Message 1 of 19

Batch Find and Replace

bmanalanDX6VM
Participant
Participant

I need to run a batch find and replace tool with AutoCAD LT.  I tried Lee Mac's Bfind LSP, but I keep getting ** Error: Automation Error. Description was not provided. **

All the changes are for a title block layout.

Any suggestions or other programs would be appreciated.

0 Likes
1,081 Views
18 Replies
Replies (18)
Message 2 of 19

pendean
Community Legend
Community Legend

@bmanalanDX6VM Lee Mac's BFIND uses LISP expressions not available in LT2024-LT2025. You are welcome to reach out to Lee Mac and offer to pay to have that code changed.

 

In the meantime: are you just wanting to swap multiple words in text/mtext/block attributes etc. at one single time inside a single DWG file?
Or do that in multiple DWG files all at once?

Or....?

0 Likes
Message 3 of 19

bmanalanDX6VM
Participant
Participant
Thank you for your reply.
I need to make 3 find and replace text on 350 dwg files. I would break them into groups.
0 Likes
Message 4 of 19

paullimapa
Mentor
Mentor

You can always download the trial version of the full AutoCAD 2025 to just complete this search and replace job


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 19

bmanalanDX6VM
Participant
Participant
I thought about that after learning the code is not supported in LT.
Thank you.
0 Likes
Message 6 of 19

paullimapa
Mentor
Mentor

you are welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 19

Sea-Haven
Mentor
Mentor

As you have LT you may have to use a script and do what you want. You can

 

Open dwg1

(load "findit")

(findit "oldtext" "newtext")

Close y

 

So repeat for the 350 dwg's the "findit lisp is exactly that replace some text with a new text, you make findit.lsp work for 1 dwg then add it to a script. I think Lt will support the look for files using VL-directory commands. So can write a script.

 

Explain more what is to be replaced random text, an attribute value in a block inserted many times and so on.

0 Likes
Message 8 of 19

ec-cad
Collaborator
Collaborator

You (can) run Lisp, if you tried Lee Mac's Bfind.lsp, and it echoed an error.

So, if you have multiple drawings that need a 'Constant String' applied to the

title blocks, then you can use a Batch program that builds a Script and runs it.

Here's a Lisp that will search for 'blockname, and up to 15 Tagnames,  if blockname is found, gets attributes, and will change the attribute textstring to your defined 'Values.

Doesn't support Dynamic Blocks, but a few lines of code can get to those as well.

The 'T in the Lisp filename means (needs Tuning) before use.

ECCAD

 

0 Likes
Message 9 of 19

bmanalanDX6VM
Participant
Participant
Thank you for the information. I was able to get BFIND to work.


Sent from my T-Mobile 5G Device
Get Outlook for Android<>
0 Likes
Message 10 of 19

Ken_McC
Observer
Observer

How were you able to get it to work??

0 Likes
Message 11 of 19

paullimapa
Mentor
Mentor

If you bypass the section of the code which uses the unsupported LT lisp function to bring up the gui to select a folder by hardcoding the folder in the code then the rest of the code LT supports then BFind should work. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 19

bmanalanDX6VM
Participant
Participant
If you are using Autocad LT, it will not run. I installed a trial version of Autocad 2025 and it worked.
You will need to download the file,"BFindV2-0.isp"
Open a dwg file and in the command line type, "Appload". Find the BFindV2-0.isp and install the program.
Next, in the command line, type "Bfind" and the program will load an input/option window where can type in your changes and how they will be applied.

Good luck.

0 Likes
Message 13 of 19

Ken_McC
Observer
Observer

Ah thanks. Installing autocad is easier said than done at a large company. We just got switched to LT from the full version of autocad and this is the first hiccup i've seen.

 

Thanks for the reply, paullimapa. I'm not good enough at lsp to cut that part out.

0 Likes
Message 14 of 19

bmanalanDX6VM
Participant
Participant
You are welcome.
Not sure about the scope of your project, but I do consulting if you need help.
Thanks for the information paullimapa on modifying the code for a work around using LT.
0 Likes
Message 15 of 19

paullimapa
Mentor
Mentor

Unfortunately, I don't have LT to attempt to modify the code to make it work.

But looks like in addition to substituting out this get folder code:

(defun _DirectoryDialog ( msg dir flag / Shell Fold Self Path )
    (vl-catch-all-apply
      (function
        (lambda ( / ac HWND )
          (if
            (setq Shell (vla-getInterfaceObject (setq ac (vlax-get-acad-object)) "Shell.Application")
                  HWND  (vl-catch-all-apply 'vla-get-HWND (list ac))
                  Fold  (vlax-invoke-method Shell 'BrowseForFolder (if (vl-catch-all-error-p HWND) 0 HWND) msg flag dir)
            )
            (setq Self (vlax-get-property Fold 'Self)
                  Path (vlax-get-property Self 'Path)
                  Path (vl-string-right-trim "\\" (vl-string-translate "/" "\\" Path))
            )
          )
        )
      )
    )
    (if Self  (vlax-release-object  Self))
    (if Fold  (vlax-release-object  Fold))
    (if Shell (vlax-release-object Shell))
    Path
  )

There's also an alert msg code that also LT does not support:

(defun _Popup ( title flags msg / wsh res )
    (vl-catch-all-apply
      (function
        (lambda nil
          (setq wsh (vlax-create-object "WScript.Shell"))
          (setq res (vlax-invoke-method wsh 'popup msg 0 title flags))
        )
      )
    )
    (if wsh (vlax-release-object wsh))
    res
  )

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 19

Sea-Haven
Mentor
Mentor

If your old fashioned like me you can get a list of dwg names to a file, you use the CMD function of windows, Dir *.dwg >dwglist.txt, once you have the file you could paste all the names into a List and run bfind removing the step to make the dwg list. Or read the file making the list required.

 

It looks like the new LT2026 has not improved the missing lisp functions.

Message 17 of 19

paullimapa
Mentor
Mentor

there are still even more functions implemented in BFindV2-0.lsp which are required to run that are not supported in LT:

;;-------------------------------------------------------------------------------;;
;;                     --=={  String Replacement Engine  }==--                   ;;
;;-------------------------------------------------------------------------------;;

  (or (vl-bb-ref '*REX*)
      (vl-bb-set '*REX* (vlax-create-object "VBScript.RegExp")))
  (defun _ObjectDBXDocument ( acapp / acVer )
    (vla-GetInterfaceObject acapp
      (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
        "ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
      )
    )
  )
  (defun _OpenFile ( fn / shell result )
    (setq result
      (vl-catch-all-apply
        (function
          (lambda nil
            (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
            (vlax-invoke shell 'open fn)
          )
        )
      )
    )
    (if shell (vlax-release-object shell))
    (not (vl-catch-all-error-p result))
  )

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 19

bmanalanDX6VM
Participant
Participant
Thank you, Sir.
0 Likes
Message 19 of 19

paullimapa
Mentor
Mentor

Once again you are welcome…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes