GREP to find any character then paragraph break

Community Beginner ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

Hello Everyone,

Newer to GREP here.  Looking to use a paragraph style the text that we enter in manually in a text box

Esentially we type like this:

V

E

R

T

I'd like to apply a paragraph style to that text box and then create various character styles based on the number of characters within the text box and have GREP in the paragraph style automaticlly the correct style.  I have this working for horizontal text but the vertical text I am having trouble writing the code.  

TOPICS
Scripting , Type

Views

125

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

How are you moving to the next line after each letter?

The last character (including any punctuation or white space) can be found with .(?=\r)

.$ should work as well, but in a quick test in CS6 which happened to be open it found 11 out of 12 characters correctly and the second-to-last cahracter once, so I'm hesitant to say it's toatally reliable.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

Not sure if it suits your situation but if you set your text as on a vertical path, stair-stepped (see example tutorial) then you can use a normal find/replace/grep to search for it.

- Mark

 

P.S. this technique uses force justify last line, which might solve your problem of having to have multiple paragraph styles? I'm only guess at how your design is laid out though. 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

Another thought... you might be able to use GREP styles in your paragraph style to set different character styles according to how long the text is. I made a quick test and it worked using the vertical-text-on-path I mentioned earlier. I got it to change the color of the whole word depending on how long the word was. See screenshot of paragraph style editor:

Screen Shot 2021-12-17 at 9.48.46 am.png

Note: the grep matching patterns I've used don't work if you have a linefeed or carriage return between characters (which I didn't because of the text-on-path technique. They could probably be adjusted to work even with linefeeds etc.

- Mark

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

Tried each of the above mentioned without any luck.  I am using a carriage break but no the type on path.  Here is an image with hidden characters shown.  The last image is of the code we are using for the horizontal resizing.  

AllaccessMitchell_0-1640020647733.png

AllaccessMitchell_1-1640020746144.png

AllaccessMitchell_2-1640020763321.png

AllaccessMitchell_3-1640020913902.png

 

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

None of what you did can work. You use paragraph returns, so it means that in each paragraph there is a single character… Use a soft line break (shift return) instead

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

And keep in mind if you do that each of the line breaks is also counted as a character...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

LATEST

Okay, if nothing else worked, here is a scripting approach. This script will find all vertical text (ie. any text story that has no paragraphs with greater than one character) and apply paragraph style based on how many paragraphs (which means word length when setting the text vertically with returns between characters).

You can adjust the script by changing the lines such as if (p < 5) styleName = "My Para Style 1". It means a word less than 5 letters will be styled in My Para Style 1, etc.

- Mark

 

/*
    Style Vertical Text
    by m1b
    here: https://community.adobe.com/t5/indesign-discussions/grep-to-find-any-character-then-paragraph-break/m-p/12607349
*/

function main() {

    var textFrames = app.activeDocument.textFrames;

    // iterate over the text frames
    for (var i = 0; i < textFrames.length; i++) {

        // ignore if not containing vertical text
        if (!textFrameIsVerticalText(textFrames[i])) continue;

        var p = textFrames[i].parentStory.paragraphs.length,
            styleName;

        // set the style based on the number of paragraphs
        if (p <= 5) styleName = 'My Para Style 1';
        else if (p <= 8) styleName = 'My Para Style 2';
        else if (p <= 12) styleName = 'My Para Style 3';
        else styleName = 'My Para Style 4';

        // apply the paragraph style
        textFrames[i].parentStory.appliedParagraphStyle = styleName;
    }

    function textFrameIsVerticalText(textFrame) {
        // returns true if the text frame's story
        // contains 0 or 1 characters per paragraph
        var paraLengths = textFrame.parentStory.paragraphs.everyItem().length;
        for (var i = 0; i < paraLengths.length; i++) {
            if (paraLengths[i] > 2) return false;
        }
        return true;
    }

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Style Vertical Text');

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines