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.
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.
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. 🙂
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:
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
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.
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
Copy link to clipboard
Copied
And keep in mind if you do that each of the line breaks is also counted as a character...
Copy link to clipboard
Copied
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');