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

Clean up script Update

New Here ,
May 25, 2021 May 25, 2021

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

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

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

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?

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

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

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

Hi Peter

 

Using the latest version, 2021 and on Mac OS.

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

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

-Manan

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

Yes, no problem, made a small test file.

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

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.

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

Ok, will do, I thought that referred to the number of 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
Community Expert ,
May 25, 2021 May 25, 2021

I mentioned the point @brian_p_dts 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

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

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?

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

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

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

Great, thanks for all your help everyone!

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