• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Need to count characters and apply a grep style

Community Beginner ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi,

I'm new in GREP style and still haven't found the answer I am searching for in this forum.

(But as you see, my english is weak!) 😕

I need too apply a grep style to a text so that it can be included in text block.

ie: I need to change the style (using a different font size for example).

The problem is that my text is made of various sentences separated by soft returns.

(it comes from a database…).

It seems that Indesign's GREP considers 'soft returns' the same than 'hard return'.

It starts counting from 0 at every soft return.

So to resume :

- my text block allows about 500 chars within my 'standard' para style.

- when I get more than 500 chars, I need to apply a different char style so that all the chars appear in the block.

- I am not allowed to modify the content I am importing from the database.

Any help is welcome.

Views

3.0K

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

correct answers 1 Correct answer

Adobe Employee , Apr 23, 2018 Apr 23, 2018

Hi,

I would suggest you explore nested styles for this use case.

For example, here i have assigned the character style "Pink" to first 10 characters in the paragraph.

The result of this then comes out to be:

You can set the paragraph style to have a bold typeface and the character style to have regular style.

-Aman

Votes

Translate

Translate
Adobe Employee ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi,

I would suggest you explore nested styles for this use case.

For example, here i have assigned the character style "Pink" to first 10 characters in the paragraph.

The result of this then comes out to be:

You can set the paragraph style to have a bold typeface and the character style to have regular style.

-Aman

Votes

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Thank you for your response!

I am afraid that it will not apply in my case because of the 'soft returns' that set the character count to 0, making the use of nested styles unuseful… I need to take in count the whole text to apply a style.

Anyway, I might try to search also in this way.

Votes

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
Guide ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi

I'm afraid you will need a script to achieve this.

Something like a "Fit text size to frame" one.

I have googled it and it seems that some exist that may do the trick. Have a look and see if they help.

Votes

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Many thanks vinny38!

I will take a look but unfortunately, I get the text from a database and it creates automatically a great number of indesign docs.

It makes the use of script a little "touchy". By using GREP, my aim was not to have to open each document to apply changes or a script. But I am not very used with script. I imagine I can apply a script to all of my docs after having created them.

Let me have a look on it!

Votes

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
Guide ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi,

That's what we write in Javascript: "… while ( app.selection[0].parentTextFrames[0].overflows ) {…}"

I mean a script where you just indicate where are the ID files (selecting a files folder) …

The script "loops" on each file, opening it, resizing the text to try to remove the "overflow", saving, closing the file and continuing on the following!

By "resizing", we could define its process as:

1/ play with the 3 parameters of the "Justification";

2/ if not enough, reapply the para style justification, resize the font size and – if not enough – play again with the 3 parameters of the "Justification";

3/ if always not enough, reapply the para style justification, resize the font size gain and – if not enough – play again with the 3 parameters of the "Justification";

4/ …

5/ …

Until no overflow!

Best,

Michel, from FRIdNGE

Votes

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 Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Michel+%5BFRIdNGE%5D  wrote

… Until no overflow!

Or until the end of time.

( Or until the user quits InDesign the hard way; whatever comes next 😉 )

Note:

There could be permanent overflow.

Regards,
Uwe

Votes

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
Guide ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Uwe, don't be so pessimist! … 

If a file is always "overflowed" at the end of script main process, the script closes it without saving it! …

At the end, the user just needs, e.g., to take a look at the "date" of the files to identify those with a problem!

Best

Michel

Votes

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 Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi Michel,

if we go into details here with scripting: Always supply a control structure in your while loop that ends the loop.
Depending on what you do to work against overflow you could do this with a counter that e.g. stops after n attempts.

Of course: In case you are working with steps that diminishes point size there is a natural limit: 0.1 🙂

But who wants to stop by that? Better establish a higher limit.

And we have to consider if the text frame is part of a story that consists of more than one text container…

Regards,
Uwe

Votes

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
Guide ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Uwe,

Of course, the script would need some "safe achievement" controls! …

But it seems to me totally playable! …

Best,

Michel

Votes

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Hi,

Looks VERY interesting. I am really uncomfortable with scripting…

I am almost a (low tech) designer 😞

I've installed and tried some scripts but  am not completely convinced.

That's why I was looking forward to a GREP style based solution.

Many thanks anyway

Votes

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
Guide ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

What you just need to do is … 1 click!

Not so difficult to play, even for a newbie! … 

Best,

Michel

Votes

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Soooorry, I didn't get it !

Thanks again

Votes

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hi everyone!

Obstination pays.

I finally found the grep style I was looking for…

(?s).{500,} seems to do the job.

(?s) seems to avoid the soft returns to restart counting from 0

{500,} counts the characters (up to 500)…

I am successfully testing it in production.

Thanks to you all for helping me.

countingCharIgnoringSR.png.

Votes

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
Guide ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Glad it works for you!

You could simply use:

.

… for the same result!

Best,

Michel

Votes

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hi MIchel,

I think '.' alone may not work in may case because of the soft returns.

My problem is to count the characters coming from the database into a text block which size is fixed.

I have to fill in this text block with texts of different lengths.

That's why I wanted to use grep styles in order to reduce the size of the text in function of the amount of characters.

The "story' is also coming with soft returns and they set the character count to 0 at every new line.

Then I find that 'formula' to ignore them and count the characters of the the whole 'story' in order to apply my character styles regarding the total number of characters imported.

I don't know if I made it clear because my english is very rusty.

Thanks for your response anyway !

Votes

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
Guide ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Emmanuel,

I understand what you mean! …

I just say I find such a way really imprecise!

Capture d’écran 2018-05-07 à 22.52.49.png

You want to play with a char approach basing on the number of chars! …

When you target X chars, then Y chars, and Z chars, you target in fact (until Y-1) chars, then (until Z-1) chars and (Z or more) chars!

More boring, in my sample, (?s).{15,} [green] targets the range 15-19 chars including the carriage-return (19th).

Note the empagement showed by the 18 "i" and the 18 "m"!

The same chars number but not really the same empagement!

Best,

Michel

Votes

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 ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

LATEST

Well !

Thanks for the demo… ;-)))

But in this case, I don't need such precision...

What I need is to spare time…

Actually, the story is composed of about 400 to 600 chars.

That means a middle of 500 (and in french, more i than w !).

The law of large numbers provides a certain regularity anyway.

Yet, I won't play with approach, but with font size.

I know, it's very bad! 😕  (yuk)

But for this particular kind of job I am doing (not so qualitative), it's ok.

I mean, generating 1000 docs without text bleed and without having to open them, is ok...

Best regards

Votes

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