FIND command that will recognize multiple lines of text at once

FIND command that will recognize multiple lines of text at once

anderson51
Advocate Advocate
3,685 Views
40 Replies
Message 1 of 41

FIND command that will recognize multiple lines of text at once

anderson51
Advocate
Advocate

Is there a find/replace lisp routine will allow you to FIND multiple lines of "hard returned" text within a leader...and REPLACE multiple lines of "hard returned" texts?

 

 

Thanks,

 

Anderson51

 

0 Likes
3,686 Views
40 Replies
Replies (40)
Message 21 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

I am unable to get it to work....


Can you post a drawing file with a few matching Mtexts, and indicate on which one you first picked as the source?

Kent Cooper, AIA
0 Likes
Message 22 of 41

ronjonp
Mentor
Mentor

Do a search for 'STRIPMTEXT' if all you're wanting to do is remove hard returns.

0 Likes
Message 23 of 41

john.uhden
Mentor
Mentor
@ronjonp :
I wrote the first Unformat code that Joe Burke and Steve Doman started with
until they took up regular expressions. If any of the candidate mtext
objects has additional formatting codes embedded, then it's gonna take more
than finding just returns. My unformat function removes all that stuff.
Well, it may be missing some more recent types of formatting, but I should
update it anyway.

John F. Uhden

0 Likes
Message 24 of 41

ronjonp
Mentor
Mentor

Nice .. that code has been around a loooong time 🙂 .. looking closer at the OP request it's not as clear to me what they really want done since the hard returns are removed but the new text is in a totally different format and the 4" size is gone.

ronjonp_0-1608244685141.png

 

0 Likes
Message 25 of 41

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

Do a search for 'STRIPMTEXT' if all you're wanting to do is remove hard returns.


@ronjonp and @john.uhden , neither STRIPMTEXT nor UNFORMAT is what they're after.  See >this< again.

Kent Cooper, AIA
0 Likes
Message 26 of 41

john.uhden
Mentor
Mentor
I am not looking at the thread right now, but going from memory, he wants
to do a multiple find and replace. But for some reason he doesn't find the
FIND command suitable.
Maybe he doesn't want to "Replace All", or maybe he wants to see the found
sentences in a different format (like on the screen) or having to hit
"Next" without also hitting "Zoom To." Presuming there may be formatting
codes other than "hard returns" that's why I mentioned unformatting and
temporarily exploding the mtext to focus on the "found" lines. Of course
I'm also a PITA for pointing out soft returns ("\n"). I'd wager that Joe
and Steve could probably do a better job at this, but you know I despise
having us spend our leisure hours to tend "the needy." I am always hoping
that the OP has the capacity to take guidance toward solving his own
problem.
I don't see what difference the 4" size is if he's looking only for
content. But I am looking at this problem from only an unformatted point
of view. Good news is that I still have a pulse. 🙂

John F. Uhden

0 Likes
Message 27 of 41

john.uhden
Mentor
Mentor
@Kent1Cooper :
Yes, but I don't think he wants to replace whole paragraphs independent of
their content, but perhaps my pulse is fading away.
I also don't see why the FIND command isn't good enough.

John F. Uhden

0 Likes
Message 28 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

I am unable to get it to work....but it very well could be operator error.


What happens when you try it?

Kent Cooper, AIA
0 Likes
Message 29 of 41

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
... for some reason he doesn't find the FIND command suitable. ....  I also don't see why the FIND command isn't good enough.

It's not for "some reason," but for a very specific one.  To help you see why:

 

Start an MTEXT command, and type in "this is" [Enter] "a test" {finish the command by whichever means you choose}.  Select the result [middle below on the black background] and see what its Contents are [Properties palette excerpt at left].  They include the \P representing the hard return causing the move to a second line of text.

ThisIsATest.PNG

As I understand it, they want something equivalent to the right part [part of a FIND dialog box] -- namely, to put "this is a test" into something, and have it find that Mtext object, despite [or "around"] the hard return within it.  FIND does not find it, even if, in the  Find what:  entry, you include the \P [as displayed in Properties] or the \\P [as listed in entity data].  That is the reason why FIND is not suitable for their intended purpose.

 

It's equally unsuitable [i.e. equally unable to find that Mtext object] if you use the Shift+Enter way of getting a new line.  And that has a weird twist:  in the Properties palette Contents slot, all that shows is the part before the new-line, i.e. only "this is", until you pick in it, then it shows "this isa test" without showing the \n that's in there, though it appears in the entity data content entry.

Kent Cooper, AIA
0 Likes
Message 30 of 41

anderson51
Advocate
Advocate

This is what shows in the command line after copying in the first line of text.

 

anderson51_0-1608308304353.png

 

When I copy in the second line of text, nothing shows in the command line

0 Likes
Message 31 of 41

Kent1Cooper
Consultant
Consultant

So did you follow the instruction and select a Source object?  [Maybe I should have included the word "Select" in the prompt.]  If you do, then paste the second line in, and what should happen is that all matching Mtext objects will be selected/highlighted/gripped, and you can give them new contents in the Properties palette.

Kent Cooper, AIA
0 Likes
Message 32 of 41

anderson51
Advocate
Advocate

Yes.

For me, it selects every piece of mtext within the dwg, regardless of the contents.

Also, copying in that second string of text, invokes the copy command for some reason?

0 Likes
Message 33 of 41

john.uhden
Mentor
Mentor
Excellent explanation, @Kent1Cooper !
Seems as though he will have to do his find and replace using his eyes.
I can't see programming a way to disassemble the mtext and put it back
together while retaining formatting, well at least not without turning my
brain into jello.
After some playing around, about the best I can do short of jello, is to
underline (with line entities) where the searched string might be found.

John F. Uhden

0 Likes
Message 34 of 41

anderson51
Advocate
Advocate

I agree, Kent did do an excellent job explaining that. 

I did indeed do a find/replace using my eyes....and it was painful as I had over 100 to do. It took the better part of the day unfortunately. 

0 Likes
Message 35 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

.... it selects every piece of mtext within the dwg, regardless of the contents.

Also, copying in that second string of text, invokes the copy command for some reason?


It doesn't do either of those for me.  However, I had forgotten that with Mtext, you can't replace contents wholesale by typing into the Contents slot in Properties, even if the objects all start with the same contents, but it needs you to step through each.  So it would need to be defined into a command that could do that to all of them at once.

Kent Cooper, AIA
0 Likes
Message 36 of 41

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

@ronjonp wrote:

Do a search for 'STRIPMTEXT' if all you're wanting to do is remove hard returns.


@ronjonp and @john.uhden , neither STRIPMTEXT nor UNFORMAT is what they're after.  See >this< again.


@Kent1Cooper  My apologies, I did not read all the posts thoroughly as I'm only 1/2 interested in this problem 😃 ... glad I did not jump down this rabbit hole. 🍻

0 Likes
Message 37 of 41

john.uhden
Mentor
Mentor

@anderson51 :

You know that I have been interested in this, mainly because of AutoCAD's inability to do what you want.

The find part isn't that hard, but the replacement could be.  For example, suppose we had the following mtext with hard (or soft) returns at the end of each displayed line...

"The quick brown

fox jumped over

the lazy dog."

and we want to replace "brown fox" with "northern grey squirrel."

I can remove all the returns to get a continuous string, but where do I put back the first return, after "northern" or after "grey" or after "squirrel?"  I'm certainly not going to attempt to distinguish adjectives from nouns.

Now if every case were to be the removal of just the entire first line, then it's easy, but it wouldn't be very popular.  Hmm... one way might be to shrink it's width to let AutoCAD apply a wrap if the added string is too long, but that's just a guess as to the desired result.

So, would it be helpful enough to just mark the finds with an ellipse or closed polyline box and leave the replacing to the user?

John F. Uhden

0 Likes
Message 38 of 41

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

....

"The quick brown

fox jumped over

the lazy dog."

....


[[ A digression....  Being the famous sentence that it is [famous for being quite short while containing every letter of the alphabet], it needs to be "jumps" or it contains no "s" -- the "e" and "d" are covered elsewhere.  There's an even shorter one I know of:  "Pack my box with five dozen liquor jugs." ]]

Kent Cooper, AIA
Message 39 of 41

john.uhden
Mentor
Mentor
Very astute, and educational too. Gotta remember the jug thing.
So, where do I put back the first return??

John F. Uhden

0 Likes
Message 40 of 41

anderson51
Advocate
Advocate

@john.uhden,

I really appreciate you and Kent looking into this and trying to help. Its problem solvers like you two that makes it fun to come to these forums looking for answers., and Kent has solved many for me and been helpful on many occasions.  

 

You two deserve the "5 dozen liquor jugs" for all the work you've put in over the years on here.

 

Cheers!

0 Likes