Jump to content

Recommended Posts

  • 7 months later...
Posted

I'm having issues with 2022.

 

See attached drawing where I'm trying to replace the multileader with the red text.

 

It's not working. BTW, I'm not using the search only checkbox and all the replace options are checked in the settings.

 

 

BFind Issue in ACAD 2022.dwg

  • 1 month later...
Posted (edited)
On 3/24/2010 at 2:06 AM, Lee Mac said:

Batch Find & Replace Text

 

This program uses ObjectDBX to perform multiple text replacements on the current drawing or a complete directory (and subdirectories) of drawings. The program has the ability to search Text, MText, Block Attributes, Multileader Text, Table Cell Text and Dimension Override Text.

 

The user may replace multiple search strings, and load & save lists of search strings for future use, saving time in program data entry.

 

Users may perform a complete Find & Replace operation, or merely search for potential replacements using the 'Search Only' option. Following a search operation, a report is displayed informing the user of the replacements which would be performed should the user proceed with the replacement. The report also displays the object containing the text to be replaced, along with the entity handle of such object, and the drawing filename in which the object resides.

 

The program provides the user additional refinement options, as displayed in the Options Dialog. This enables the user to control which objects are searched, whether locked layers are included in the replacement, search item case-sensitivity and whether the search item must appear as a complete word to be replaced.

 

The generation of a report following a text replacement may also be controlled within the Options Dialog (the report will always be created following a search operation).

 

Help and examples can be found in the Code Header:

Dialog Preview:

 

http://lee-mac.com/lisp/gifs/BFindV2-0-1.png http://lee-mac.com/lisp/gifs/BFindV2-0-2.png

 

Options Dialog:

 

http://lee-mac.com/lisp/gifs/BFindV2-0-3.png

 

Function Syntax: BFind

 

 

;;-------------------------=={  Batch Find & Replace  }==------------------------;;
;;                                                                               ;;
;;  Will Find and Replace multiple strings entered by the user within Text,      ;;
;;  MText, Block Attributes, MLeader Text, Table Text and Dimensions within the  ;;
;;  current drawing, all currently open drawings and/or a directory              ;;
;;  (and subdirectories) of drawings.                                            ;;
;;                                                                               ;;
;;  If the 'Block Definitions' option is selected, all instances of the          ;;
;;  aforementioned text objects residing within block definitions are included   ;;
;;  in the search domain.                                                        ;;
;;                                                                               ;;
;;  Furthermore the user may choose which objects to search, whether the find    ;;
;;  string is case sensitive, and whether to restrict the search to whole words  ;;
;;  only.                                                                        ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  BFind                                                      ;;
;;                                                                               ;;
;;  Notes:                                                                       ;;
;;  ---------                                                                    ;;
;;  As expected, the known bug with ObjectDBX arises with regards to attribute   ;;
;;  alignment following modification. A sub-function has been included in an     ;;
;;  attempt to correct the change in position, however, a slight shift in        ;;
;;  position may be noticed. The attribute is realigned when the block is moved  ;;
;;  manually.                                                                    ;;
;;                                                                               ;;
;;  Also, when using the Batch Find and Replace, drawing thumbnails are lost     ;;
;;  upon saving with ObjectDBX. These return when the drawing is saved manually. ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com                          ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;                                                                               ;;
;;  With additional thanks to Joe Burke for his tremendous help towards using    ;;
;;  Regular Expressions to eliminate the problem of MText formatting codes when  ;;
;;  performing replacements.                                                     ;;
;;                                                                               ;;
;;-------------------------------------------------------------------------------;;
;;  Version:                                                                     ;;
;;                                                                               ;;
;;  1.0:  24/05/2010  -  First Release                                           ;;
;;-------------------------------------------------------------------------------;;
;;  1.1:  26/05/2010  -  Added Options Button.                                   ;;
;;                    -  Updated String Replacement functions to allow for case  ;;
;;                       sensitivity options.                                    ;;
;;                    -  Upgraded StringRep function to allow replacement string ;;
;;                       to contain find string.                                 ;;
;;                    -  Fixed bug causing an unsaved drawing to be saved.       ;;
;;-------------------------------------------------------------------------------;;
;;  1.2:  29/05/2010  -  Added ability to perform multiple replacements.         ;;
;;-------------------------------------------------------------------------------;;
;;  1.3:  31/05/2010  -  Added ability to edit find and replace entry by         ;;
;;                       double-clicking.                                        ;;
;;                    -  Added 'Table Text' object to Options Dialog.            ;;
;;                    -  Added 'Find Whole Words Only' option to Options Dialog. ;;
;;                    -  Redesigned Options Dialog to accommodate new toggles,   ;;
;;                       added mnemonics.                                        ;;
;;-------------------------------------------------------------------------------;;
;;  1.4:  27/04/2010  -  Replaced 'StringRep' function with functions utilising  ;;
;;                       Regular Expressions to allow for MText formatting.      ;;
;;-------------------------------------------------------------------------------;;
;;  1.5:  29/09/2010  -  Reformatted code.                                       ;;
;;                    -  Drawings only saved if a replacement is made.           ;;
;;-------------------------------------------------------------------------------;;
;;  1.6:  03/10/2010  -  Added pick buttons to select text for Find/Replace      ;;
;;                       strings.                                                ;;
;;                    -  Added 'Match Case' option                               ;;
;;                    -  Added 'Find Whole Words Only' option                    ;;
;;-------------------------------------------------------------------------------;;
;;  1.7:  05/10/2010  -  Added 'Search Only' option in which the program will    ;;
;;                       search for multiple strings within the current drawing  ;;
;;                       and/or a directory (and subdirectories) of drawings,    ;;
;;                       subsequently producing a report detailing the number    ;;
;;                       of occurrences of each string and list of possible      ;;
;;                       changes should a replacement be performed.              ;;
;;                    -  Added error trap to drawing processing loop to prevent  ;;
;;                       crash should one drawing error.                         ;;
;;                    -  Added delay to DCL creation.                            ;;
;;-------------------------------------------------------------------------------;;
;;  1.8:  08/10/2010  -  Added Load & Save buttons to allow a set of search      ;;
;;                       items to be loaded and saved.                           ;;
;;-------------------------------------------------------------------------------;;
;;  1.9:  09/10/2010  -  Fixed bug involving capital 'S' being removed from      ;;
;;                       textstring during stacking formatting code removal.     ;;
;;                    -  Added code to allow 'special' characters to be used in  ;;
;;                       Find string.                                            ;;
;;-------------------------------------------------------------------------------;;
;;  2.0:  22/07/2011  -  Majority of program rewritten and reformatted to        ;;
;;                       include the following enhancements:                     ;;
;;                    -  Fixed tab stops in dialog to allow the user to use the  ;;
;;                       tab key to navigate between edit boxes.                 ;;
;;                    -  Added 'Where to Search' panel to allow the user to      ;;
;;                       restrict the search to Modelspace, Layout space or Both.;;
;;                    -  Added 'Block Definitions' to list of objects to search  ;;
;;                       to allow users to search text objects in blocks.        ;;
;;                    -  Added 'Current Directory' toggle to allow the user to   ;;
;;                       quickly select the current working directory to be      ;;
;;                       processed.                                              ;;
;;                    -  Added ability to add items to find/replace list by      ;;
;;                       pressing Enter from within either edit box.             ;;
;;                    -  Added ability to press Enter after entering Save        ;;
;;                       Reference without needing to click the OK button.       ;;
;;                    -  Added ability to press Enter after editing entry        ;;
;;                       without needing to click the OK button.                 ;;
;;                    -  Changed format of Saved Searches file for easier        ;;
;;                       manual editing.                                         ;;
;;                    -  Added ability to process 'All Open Drawings'.           ;;
;;-------------------------------------------------------------------------------;;
 

 

 

A full description can be found here.

 

Disclaimer: BFind.lsp is not entirely bug-free, as demonstrated by the information contained herein: I would hence advise against its usage in cases where heavily formatted MText is involved. However, it should, in most cases, perform successfully.

 

When replacements are made, drawings will be saved in native format (i.e. if run in AutoCAD2010, will be saved as 2010 drawing).

BFindV2-0.lsp 79.94 kB · 1,809 downloads

@Lee Mac sir,in bfind lisp , Is possible to copy paste from excel.

In Excel one column I have old text and another column new text..

Currently in your lisp need to type one by one.

Please update your program to copy paste or upload excel or CSV. 

Thanks

Edited by Ish
Change
Posted
10 hours ago, Ish said:

@Lee Mac sir,in bfind lisp , Is possible to copy paste from excel.

In Excel one column I have old text and another column new text..

Currently in your lisp need to type one by one.

Please update your program to copy paste or upload excel or CSV. 

Thanks

 

You might get a better reply asking Lee Mac directly via his website rather than hoping that he has the time to pass by here in the next few days.

 

I think in essence this is what you are wanting: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-and-replace-text/td-p/5649883 which is a find and replace LISP run through the command line rather than via a dialogue box.... and of course if it can run solely via the command line you can send inputs to it by another LISP....

 

So your task today is then to find a LISP that will read the values from an excel file, use one of the batch processing LISPs and add it all together.

 

I am not sure what your level of writing LISPs is, and I don't really grab text from excel - I don't have a handy example of that part for you, but someone else will if needed, and if you look through Lee Macs website he has a script editor (or the core console will do the same) which will do the batch part for you.. all you need is to grab these parts and put it all together... but of course, ask and let us know where you need the next bit of help

  • 2 years later...
Posted (edited)
On 3/24/2010 at 1:06 AM, Lee Mac said:

BFindV2-0.lsp 79.94 kB · 1,826 downloads

Edited July 22, 2011 by Lee Mac

I want to find and replace two (or 3) lines of Mtext with another two (or 3) lines of Mtext.
You can use the lee-mac BFind V2-0 program with some additional manipulations.
In order for the MText to remain two-line (3-line...) and in general the program works, you need to Find
and Replace all the "\R" (dividing the text into lines) for the selected texts in the window, then the replacement will occur and the text will remain two-line.
Mtext of the form:
String 1 
String 2 
String 3

in the Find a single line entry window,

String 1 \PString 2 \PString 3

but with \P that is, the string:
String 1 \PString 2 \PString 3
it should look like this
String 1 String 2 String 3
The same must be done for the line in the Replace window...
The replacement is not always performed correctly...
Is it possible to make a simplified version of BFind V2-0 without batch processing (only for the current drawing), but with the ability to find and replace Mtexts in several line?

BFIND1.png

BFIND2.png

Edited by Nikon
Posted

If you want one dwg only at a time then you can get the string "AAA\\PBBB\\PCCC".

 

You can then pull it apart ("AAA" "BBB" "CCC") for me using multi getvals.lsp I would pop a dcl with each line as an entry up to about 15 lines works. Then change the required values and update even multiple Mtext. Look in downloads fo the lisp.

 

I seem to recall splitting the mtext by using string replace \\P now * then using Lee's split string. 

 

For multiple dwgs version 2 using OBDX. 

 

I will let you work out how to search for multiple mtext. The method does work. 

; tab 9 space 32 (chr 32) comma 44 semicolum 59 slash / 47 ~ 126

; thanks to Lee-mac for this defun
(defun c:test ( / )
(defun csv->lst126 ( str / pos )
(if (setq pos (vl-string-position 126 str))
    (cons (substr str 1 pos) (csv->lst126 (substr str (+ pos 2))))
    (list str)
    )
)

(setq obj (vlax-ename->vla-object (car (entsel "\nPick mtext object "))))
(setq str (vlax-get obj 'textstring))
(setq str2 str)
(while (> (setq pos (vl-string-search "\P" str)) 0)
(setq str (vl-string-subst "~" "\P" str pos))
(setq pos (vl-string-search "\\" str))
(setq str (vl-string-subst "" "\\" str pos))
)

(setq lst (csv->lst126 str))
(setq lst2 '() x 1)
(foreach val lst 
(setq lst2 (cons (strcat "Line" (rtos x 2 0)) lst2))
(setq lst2 (cons 20 lst2))
(setq lst2 (cons 19 lst2))
(setq lst2 (cons val lst2))
(setq x (1+ x))
)
(setq lst2 (reverse lst2))
(setq lst2 (cons "Please edit" lst2))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm lst2))

(setq x 0 newstr "")
(repeat (- (length ans) 1)
(setq val (nth x ans))
(setq newstr (strcat newstr val "\\P"))
(setq x (1+ x))
)
(setq newstr (strcat newstr (nth x ans)))

(vlax-put obj 'textstring newstr)
(princ)
)

Multi GETVALS.lsp

  • Thanks 1
Posted (edited)
8 hours ago, BIGAL said:
; thanks to Lee-mac for this defun
(defun c:test ( / )
(defun csv->lst126 ( str / pos )
(if (setq pos (vl-string-position 126 str))

This code selects MText.
If you enter a different text in this window, only one text will be replaced,
but I need to find and replace a lot of Mtexts...

Image 1.png

There are no 2 lines here???

Image 2.png

There are 2 lines here.

Edited by Nikon
Posted

You are out to 283 posts so it is time you started to have a go at making lisps. I have supplied the "change the mtext",  you need to add the ssget, a repeat and check does foundstr=oldstr if yes then change foundstr.

  • Thanks 1

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