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

Selecting always third and forth letter in a word and change their character style

Explorer ,
Nov 09, 2023 Nov 09, 2023

Hello everyone! 

I ran into an interesting problem. I need to select the third and fourth letters in 2400 words (these are number combinations, for example 0101A / 0102A... etc.) and change their style (make them bigger and more prominent). Is there any way to do this in bulk using a script in Indesign? I'm sure there is but I can't find a source to refer to, like the Find/Replace function. At the moment I do it by splitting the words into 3 columns in Excel and inserting them into Indesign by merging data. It's a good pretty quick option but I think indesign can play with it much more elegantly. Anyone have any ideas? I would be very grateful for everyone's help!

There is example of what I need: 

original:

01.PNG

what I need:

02.PNG

 

Thanks! 

Sending greetings from Czech Rep. 

Martina

TOPICS
Feature request , How to , Scripting , Type
805
Translate
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 2 Correct answers

Participant , Nov 09, 2023 Nov 09, 2023

If each word is in its own text frame, this should do the job:

var st = app.activeDocument.stories;

for(i=0; i<st.length; i++) {
	if(st[i].characters.length >= 3 ) {
		st[i].characters[2].fontStyle = st[i].characters[3].fontStyle = "Bold";
		st[i].characters[2].pointSize = st[i].characters[3].pointSize = 14;
	}
}

 

Before:

b1.PNG

 

After: 

a1.PNG

 

Translate
Community Expert , Nov 09, 2023 Nov 09, 2023

Would a nested style work?

 

This works like the examples given, so long as each affected word is in its own paragraph…

Screenshot 2023-11-09 at 1.06.00 AM.png

 

This works if there are multiple words in a paragraph (but only if you want every word affected)…

Screenshot 2023-11-09 at 1.08.03 AM.png

 

If you need the format applied selectively within text then you might need to use GREP, which matches specific and complex patterns (e.g. only five letter words that start with numbers and contain letters).

Translate
Participant ,
Nov 09, 2023 Nov 09, 2023

If each word is in its own text frame, this should do the job:

var st = app.activeDocument.stories;

for(i=0; i<st.length; i++) {
	if(st[i].characters.length >= 3 ) {
		st[i].characters[2].fontStyle = st[i].characters[3].fontStyle = "Bold";
		st[i].characters[2].pointSize = st[i].characters[3].pointSize = 14;
	}
}

 

Before:

b1.PNG

 

After: 

a1.PNG

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Translate
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
Explorer ,
Nov 09, 2023 Nov 09, 2023

@GNDGN THANK YOU SO MUCH!! 

This is game changer 😄 😄 I knew there will be a way. 

 

This briliatnt. Working perfectly for me! 

 

Translate
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 ,
Nov 09, 2023 Nov 09, 2023

Would a nested style work?

 

This works like the examples given, so long as each affected word is in its own paragraph…

Screenshot 2023-11-09 at 1.06.00 AM.png

 

This works if there are multiple words in a paragraph (but only if you want every word affected)…

Screenshot 2023-11-09 at 1.08.03 AM.png

 

If you need the format applied selectively within text then you might need to use GREP, which matches specific and complex patterns (e.g. only five letter words that start with numbers and contain letters).

Translate
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
Explorer ,
Nov 09, 2023 Nov 09, 2023

Wow, this also looks great - I will tested! Thank you so much. @Scott Falkner 

Translate
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
Explorer ,
Nov 09, 2023 Nov 09, 2023

So this also work perfectly for me! 

Translate
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
Participant ,
Nov 09, 2023 Nov 09, 2023

second and third letters or numbers of every word

GREP Style:

\b(\w\w)\K\w\w

 

All roads lead to Rome

Translate
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
Participant ,
Nov 09, 2023 Nov 09, 2023
LATEST

Hello @Martina zstudio 

 

and the other grep:

.{2}(?=.\t|.$)

For use in GREP Style in paragraph style* ou in Find/Change.

 

* This is the best way because the text is automatically formatted wherever the paragraph style is applied. However this will always be an indirect formation, for PDF and the like it will be kept. For copying and pasting between applications, it may not work at the destination.

 

grep.png

 

Translate
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