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

Clean up script Update

New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Hi All, I have a script that was created a few years back which cleans up text throughout a document prior to translation. But recently I have not been able to get it to work. I know nothing about scripting, but here it is. Is there anyone here who can fix it?

 

const kerningConstant = 0;
var doc = app.activeDocument,
stories = doc.stories,
story, text, found, s, t, i;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
found = doc.findGrep();
if (found.length > 1) {
for (i = 0; i < found.length; i++) {
//$.writeln( i + " - " + found[i].constructor.name + "/"+ found[i].contents );
found[i].changecase(ChangecaseMode.UPPERCASE);
}
app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
doc.changeGrep();
}

for (var s = 0; s < stories.length; s++) {
story = stories[s];
for (var t = 0; t < story.texts.length; t++) {
text = story.texts[t];
text.kerningValue = kerningConstant;
text.verticalScale = 100;
text.horizontalScale = 100;
text.tracking = 0;
}
}

TOPICS
Scripting

Views

556

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Hi @dtps10902263,

You did not mention what is not working, I see that the change of case was something that seems to be broken. So your code finds text with ALL CAPS and then if the found text is more than 1 it changes the case to uppercase and then tries to change capitalization to NORMAL. This fails, if you want the text to be finally in NORMAL capitilization you can try the following code snippet

 

const kerningConstant = 0;
var doc = app.activeDocument,
stories = doc.stories,
story, text, found, s, t, i;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = ".+";
app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
found = doc.findGrep();
if (found.length > 1) {
	app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
	doc.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
for (var s = 0; s < stories.length; s++) {
	story = stories[s];
	for (var t = 0; t < story.texts.length; t++) {
		text = story.texts[t];
		text.kerningValue = kerningConstant;
		text.verticalScale = 100;
		text.horizontalScale = 100;
		text.tracking = 0;
	}
}

 

-Manan

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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Hi Manan

 

Thanks for that, but the all caps bit still does not work for me. It stays as all caps, does it work for you?

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Which version of InDesign do you use? And which platform?

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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Hi Peter

 

Using the latest version, 2021 and on Mac OS.

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Yes, it does. I tested it on a MAC with InDesign 2021. Can you share a sample document that has this problem?

-Manan

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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Yes, no problem, made a small test file.

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

You only have one instance of cap text here, so if (found.length > 1) is not executing. Change it to if (found.length > 0)

After making that change it worked for me on PC.

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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Ok, will do, I thought that referred to the number of letters!

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I mentioned the point @brianp311 mentioned in my post as well. So changing it to 0 should work for you. I did not change it thinking you must be aware of it as you mentioned you have been using this script in previous versions, and this aspect should not be different across the versions.

-Manan

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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Ok, so now it removes ALL CAPS but it has changed to lower case as opposed to upper case. What is the command for this? the script says NORMAL, does that mean lowercase?

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 ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

That means no case is applied to the text. It's however they were typed in. There are some title case scripts, like: https://creativepro.com/files/kahrel/indesign/title_case.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
New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

LATEST

Great, thanks for all your help everyone!

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