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

Tracking/Kerning using grep in script

Enthusiast ,
Jul 07, 2024 Jul 07, 2024

Copy link to clipboard

Copied

Hi

I want to give a tracking value of 100 after an opening paranthesis and before closing paranthesis but I want to do this using a script.

 

I already have a grep query in place for after opening parenthesis: (\x{0028})(?=\S)  and replace is empty. Just add tracking value of 100. If its possible to add kerning value, it will be very good.

 

The grep query for closing parenthesis: (\x{0029})(?=\s) but there the tracking is not working as expected. It is increasing tracking after the closing parenthesis, I want tracking before closing parenthesis.

 

My first preference would be using kerning. I already have Peter's script in place, which works just fine.

Actually I need this because I want to include it in another script.

 

I have come up with this :

doc = app.activeDocument;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = '(\x{0028})(?=\S)';
app.changeGrepPreferences.changeTo = "how to add tracking/kerning here";
doc.changeGrep();

 

How can I include this in a script?

Thanks

TOPICS
How to , Scripting

Views

204

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 2 Correct answers

Enthusiast , Jul 07, 2024 Jul 07, 2024

Ok, I found the solution.

 

Here is my final code:

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=(\\x{0028}))(?=\\S)";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=\\w)(?=\\x{0029})";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

 

How can I make it better ?

Thanks

Votes

Translate

Translate
Community Expert , Jul 07, 2024 Jul 07, 2024

Your code works fine, the kerning is applied at the correct places. You could simplify the search strings a bit as follows:

"\\(\\K(?=\\S)"
"\\w(?=\\))"

but your code works as it is.

Votes

Translate

Translate
Enthusiast ,
Jul 07, 2024 Jul 07, 2024

Copy link to clipboard

Copied

Ok I have comeup with this:

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(\\x{0028})(?=\\S)";
app.changeGrepPreferences.tracking=200;
app.activeDocument.changeGrep();

How to solve the space not coming before closing parenthesis ?

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
Enthusiast ,
Jul 07, 2024 Jul 07, 2024

Copy link to clipboard

Copied

Ok, I found the solution.

 

Here is my final code:

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=(\\x{0028}))(?=\\S)";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=\\w)(?=\\x{0029})";
app.changeGrepPreferences.kerningValue=100;
app.activeDocument.changeGrep();

 

How can I make it better ?

Thanks

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 ,
Jul 07, 2024 Jul 07, 2024

Copy link to clipboard

Copied

Hi @shahidr100 , Specific kerning values need to be applied to an insertionPoint. I can't post any code at the moment, but you should be able to get the insertionPoint after the closed parenthesis and set an amount.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#InsertionPoint.html

 

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
Enthusiast ,
Jul 08, 2024 Jul 08, 2024

Copy link to clipboard

Copied

LATEST

@rob day Thank you so much Rob

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 ,
Jul 07, 2024 Jul 07, 2024

Copy link to clipboard

Copied

Your code works fine, the kerning is applied at the correct places. You could simplify the search strings a bit as follows:

"\\(\\K(?=\\S)"
"\\w(?=\\))"

but your code works as it is.

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
Enthusiast ,
Jul 08, 2024 Jul 08, 2024

Copy link to clipboard

Copied

@Peter Kahrel Thank you so much Peter. I really appreciate 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