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,675 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,676 Views
40 Replies
Replies (40)
Message 2 of 41

john.uhden
Mentor
Mentor

Okay.  I'm just ignorant enough to ask what you mean by "hard returned."

To me you might be referring to lines of mtext that don't wrap to the next line but are forced by a "hard return" ("\\P").  That would distinguish "Hello <wrap>World" from "Hello\\PWorld."

Of course if you unformat the text string (I have the original code for that) and remove the "\\P"s (and other formattting codes) then it would be the same as a wrap.  Might you have an example of what you are trying to find?

John F. Uhden

0 Likes
Message 3 of 41

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

....  I'm just ignorant enough to ask what you mean by "hard returned."

To me you might be referring to lines of mtext that don't wrap to the next line but are forced by a "hard return" ("\\P").  .....  Might you have an example of what you are trying to find?


This is a transfer to this Forum of another thread started in the AutoCAD Forum, >here<.  Yes, it's about a new line caused by a hard return [Enter] rather than Mtext-box-width word wrapping.  There is an example there.

Kent Cooper, AIA
0 Likes
Message 4 of 41

Kent1Cooper
Consultant
Consultant

Are they always in the same format?  I made one like your "before" example, and this is how the text content shows in Properties:
TextContent.PNG

Are yours always an imperial size with %%C making the diameter symbol, followed by a space and UP [or, presumably, DN], followed by the new-line return represented as \P, followed by the bracketed metric equivalent?  If so, an AutoLisp routine could certainly be written that will find all Mtext objects with content formatted like that, and replace it with just the metric text followed by the diameter symbol, space, and UP [or DN] as in your example.

Kent Cooper, AIA
0 Likes
Message 5 of 41

john.uhden
Mentor
Mentor

I don't get UP vs. DN.  Looks to me like a 4"Ø Utility Pole but that's kinda skinny.

How about the difference between "\n" and "\P?"

John F. Uhden

0 Likes
Message 6 of 41

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... How about the difference between "\n" and "\P?"


I don't think "\n" ever occurs as a new-line code in Mtext content -- it's the AutoLisp new-line for things like prompts.  They're talking about finding this kind of multiple line content in existing Mtext objects.

Kent Cooper, AIA
0 Likes
Message 7 of 41

john.uhden
Mentor
Mentor
You can create a new line feed without making a new paragraph by using
Shift+Enter, just like MS Word. It shows up as "\n."

John F. Uhden

0 Likes
Message 8 of 41

anderson51
Advocate
Advocate

Kent,

I was just giving the 1 example. I could see this being super useful with any string of text.

 

Thanks for your help

0 Likes
Message 9 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

.... I could see this being super useful with any string of text. ....


How do you envision this working?  Like FIND, where you enter a text string, and it finds objects including it even if that crosses from one line through a hard return to the next line?  I am picturing a routine looking for Mtext with "\\P" in string content, in an (ssget) function, which can find things containing such hard returns [and "\n" could be added, if it should also find things done with Shift+Enter as @john.uhden describes].  This will select/grip/highlight all Mtext objects that contain the \\P variety of new-line return, anywhere in them:
  (sssetfirst nil (ssget "_X" '((0 . "MTEXT") (1 . "*\\P*"))))

 

But suppose you were looking for things containing "this is a test" that might be wrapping to a new line in such a way.  Presumably you would want to find them even if there was no such new-line wrapping, too, or if it wraps caused by box width rather than by Enter, as regular FIND will.  If it wraps, the object's text content could contain "this\\Pis a test" or "this is\\Pa test" or "this is a\\Ptest" or any of them with a space adjacent to the Enter, on either side, such as "this is \\Pa test".  An AutoLisp (ssget) function can't search for a specific string of characters with another set of other characters that might fall anywhere within it [or not at all] -- it needs something more specific to work with.  I'm having a hard time imagining how to cover all the possibilities.  And replacing it would have similar complications -- suppose you wanted to replace "this is a test" with "I give up", how should it position the \\P in the replacement content?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 10 of 41

pendean
Community Legend
Community Legend

Wish you would still take the time to explain what problem you are trying to solve with screenshots and an actual DWG sampe file.

 

Here is what you posted in the other thread last time, I assume you still want to to do the same, namely remove/delete the first line of textand replace it with the second line of text

 

Capture.PNG

0 Likes
Message 11 of 41

Kent1Cooper
Consultant
Consultant

@pendean wrote:

.... remove/delete the first line of textand replace it with the second line of text


It's not as simple as that.  It's to replace the imperial measurement part of the first line with the metric measurement, with the Ø and the space and the UP in the first line retained, but now following the metric measurement, and eliminate the brackets around the metric one.

 

But see Message 8.  That's just one example -- what they really want it to be able to find a text string within Mtext objects even if it may have a hard return within it somewhere forcing a new line.

Kent Cooper, AIA
0 Likes
Message 12 of 41

pendean
Community Legend
Community Legend
Forgive me if I made it sound that it was going to be easy 🙂
0 Likes
Message 13 of 41

anderson51
Advocate
Advocate

Im not sure how I can explain any more simple than I have.

 

There is no reason to post a dwg. you can recreate it faster than me posting anything.

Simply invoke the Mleader command, type some text, hit enter, type some more text.....

 

I am looking for way to do a FIND/REPLACE on that MLeadered string of text that has ALL of the text included.

 

Make sense???

0 Likes
Message 14 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

.... a FIND/REPLACE on that MLeadered string of text that has ALL of the text included. ....


If ALL the text includes the hard return always included and always in the same place, that's not hard.  If you'd select an object and want to find all others with the same text content in the same configuration in those respects, that can be done:

 

(setq mt (car (entsel "\nSource object for text-content replacement: ")))

(sssetfirst nil (ssget "_X" (vl-remove-if-not '(lambda (x) (member (car x) '(0 1))) (entget mt))))

 

Then all objects of the same object type and with the same text-string content [including any hard returns if any, of either variety, in the same position within each] will be selected/highlighted/gripped, and you can put your replacement text content right in the Contents slot in the Properties palette.

Kent Cooper, AIA
0 Likes
Message 15 of 41

john.uhden
Mentor
Mentor
Finding the string is not a huge problem, but replacing it is if you want
to retain whacko formatting overrides mixed in like fruit in Jello. It's
easier for me 'cause I disdain the formatting overrides and have the
UNFORMAT function (which anyone may have).
I was thinking that the best way to show the findings (and even to find
them) would be to temporarily explode the mtext into separate pieces of
text, highlight them in any number of ways, and then either reassemble them
or Undo the explosion. Of course you could explode a copy of the mtext and
not have to Undo. But exploding would lose both the "\n"s and the "\P"s,
so maybe it would be better to create a hybrid @str2list function that
separated strings by either/or. You could put the candidate strings in a
list_box too. Somewhere I think I created a horizontal slider function
that enabled scrolling to see the full contents of any line of text. I
guess that's where VBA and ObjectDCL have their advantages, or am I
forgetting some regular DCL capabilities?

John F. Uhden

0 Likes
Message 16 of 41

anderson51
Advocate
Advocate

This sounds like the answer. How do I use this?

 

Thanks,

 

Anderson

0 Likes
Message 17 of 41

Kent1Cooper
Consultant
Consultant

@anderson51 wrote:

This sounds like the answer. How do I use this? ....


Try it first, by just copying/pasting in at the command line, one line at a time [the first line first, and follow the selection instruction, then paste in the second line].  If it does what you want, it can be defined into a command name you could type in, and/or put into a Tool Palette button you could pick on.

Kent Cooper, AIA
0 Likes
Message 18 of 41

john.uhden
Mentor
Mentor
Um, what about the (multiple) 3s provided by entget?
Methinks one must use objects and properties.
Oh, wait...
(apply 'strcat (mapcar 'cdr (vl-remove-if-not '(lambda (x)(vl-position (car
x) '(1 3)) (entget mt))))
**
*I'd better get home and sober up with a cocktail. Work makes my head
spin.*

John F. Uhden

0 Likes
Message 19 of 41

anderson51
Advocate
Advocate

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

0 Likes
Message 20 of 41

john.uhden
Mentor
Mentor

In 2002, a Shift+Enter created a new paragraph (\P).

But in C3D 2020, this is what you get...

Command: (entget (car (entsel)))

Select object: ((-1 . <Entity name: 7ffffb313d0>) (0 . "MTEXT") (330 . <Entity name: 7ffffb039f0>) (5 . "832D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "C-ANNO-MATC-PATT") (100 . "AcDbMText") (10 2411.48 7448.37 0.0) (40 . 0.2) (41 . 77.5479) (46 . 0.0) (71 . 1) (72 . 5) (1 . "This is an mtext test in C3D 2020<hitting Shift+Enter>\nThis is the next line\nand another.")

 

I may be an old fart, but I still have a pulse (I just checked).

John F. Uhden

0 Likes