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

Cleaning up script

New Here ,
Jun 01, 2011 Jun 01, 2011

Hello All

We often translate indesign files using a CAT tool to open the idml file. But most of the InDesign files we are sent have been created by people who take a great many short cuts to get things to fit, which maybe good for them but not for us.

We need a script that can set all kerning to 0 or a constant value throughout a document, remove all stretched text and change any thing with ALL CAPS to true uppercase.

There are a few more niggly things we have to do to clean it up which can take a few hours for a large document so it would be good it there was a script that could do this or if anyone knows how to create one for us we would be happy to work with you to create it.

TOPICS
Scripting
2.7K
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 1 Correct answer

Valorous Hero , Jun 02, 2011 Jun 02, 2011

Here is a new version:

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

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

function ChangeCase(text) {
     var i, found;
     if (text.contents != "") {
          ap

...
Translate
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

Here is a simple script to get you started:

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

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

It's not clear to me what you do with ALL CAPS in InDesign — do you turn them off and retype the text manually with Caps Lock on?

Regards,

Kas

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 ,
Jun 02, 2011 Jun 02, 2011

Hi Kas

Thanks for that, I shall try it out.

When we come across text that is using the 'ALL CAPS' control we select the text and turn this off, then use a shortcut to convert to uppercase, using the type/change case/uppercase command.

The problem is when we upload to our CAT tool everytime there is a change to the formating in a word then 'tags' are inserted where a change begins and ends, so if a designer has been mucking about with kerning, tracking, scaling text etc or has been using "ALL CAPS" on some letters and not on others (yes we can have half a word in All CAPS and half in true uppercase!) then text can look like this to the translator.

T*h**is i**s v*e**ry d*i*ffi**cu*lt to* re*ad *text*

As we typeset the text after translation in InDesign we add our own tweaks where necessary.

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

OK. I see now: we can use the changecase method.

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

Here is a new version:

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

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

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

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 ,
Jun 02, 2011 Jun 02, 2011

Hi Kas

Ok, my scripting abilities are pretty non existent, I copied the script and pasted it into a text doc and saved it with .jsx on the end and save it to the scripts folder. It shows up in InDesign but does not do anything, what did I do wrong?

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 ,
Jun 02, 2011 Jun 02, 2011

tell a lie...it did change kerning to 0 and the scaling to 100% but the caps did not change to uppercase. I am assuming these are dfferent things.

Can you add tracking to that mix as well, tracking to 0.

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

Can you add tracking to that mix as well, tracking to 0.

text.tracking = 0;

I think this line should do the job.

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 ,
Jun 02, 2011 Jun 02, 2011

Hi Kas

Added that line and it works, amazed myself. The only but that does not is the caps bit.

Does this script work on the whole document or just the story, text box you are in?

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

Let's try this version.

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

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

          text.tracking = 0;
     }
}

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.constructor.name + "/"+ found.contents );
          found.changecase(ChangecaseMode.UPPERCASE);
     }
     app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
     doc.changeGrep();
}

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

Here I posted a couple of samples: before and after running the script. Try to run it against the 'before' sample.

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 ,
Jun 03, 2011 Jun 03, 2011

Hi Kas

That worked perfectly....

Many thanks for your help, I shall be incontact outside of this forum if we need your expertise again.

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 ,
Jun 03, 2011 Jun 03, 2011

Hi Kas

Just realised the text which was all caps was unaffected by the commands to set kerning to 0, was this because of the order the script is carried out in?

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
Valorous Hero ,
Jun 03, 2011 Jun 03, 2011
LATEST

Just realised the text which was all caps was unaffected by the commands to set kerning to 0, was this because of the order the script is carried out in?

Yes, it was. Here's a new version:

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 > 0) {
     for (i = 0; i < found.length; i++) {
          //$.writeln( i + " - " + found.constructor.name + "/"+ found.contents );
          found.changecase(ChangecaseMode.UPPERCASE);
     }
     app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
     doc.changeGrep();
}

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

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
Valorous Hero ,
Jun 02, 2011 Jun 02, 2011

The script should be in the Scripts Panel folder, not Scripts.

This version is very basic so it doesn't do any error testing: e.g. if a document is open, etc. You also haven't mentioned which version of ID you use; I wrote this for CS5.

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
LEGEND ,
Jun 02, 2011 Jun 02, 2011
The problem is when we upload to our CAT tool everytime there is a change to the formating in a word then 'tags' are inserted where a change begins and ends, so if a designer has been mucking about with kerning, tracking, scaling text etc or has been using "ALL CAPS" on some letters and not on others (yes we can have half a word in All CAPS and half in true uppercase!) then text can look like this to the translator.

You do realize that trying to solve this problem in InDesign is not the right solution.

You will forever have these kinds of problems.

The right answer is to postprocess the IDML, such as with XSLT, and remove the extraneous tags.

What does your CAT tool look at? Does it just look at the <Content/> tags inside the story files, or is it more complicated?

Do you care about paragraph breaks?

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 ,
Jun 03, 2011 Jun 03, 2011

Thanks for the response, but this is the right way to go for us. Tried and tested, we just needed to automate it.

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
LEGEND ,
Jun 03, 2011 Jun 03, 2011

OK, well, when you start having more problems because of other kinds of formatting and overrides, please reconsider. If so, answers to the questions above would be a good start at making it work. It's probably not too difficult, either.

Though thinking some more, I have to wonder why you start with IDML if your translation is not really about formatting -- it would seem like exporting to text would just work better...unless you have a lot of stories? Even so...

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 ,
Jun 03, 2011 Jun 03, 2011

Hi John

We use a CAT tool called XTM which enables us to upload an idml file. When the translator starts translating all they see is the text with [1]tags like this,[1] [2] this denotes different formatting[2]. If we do not take out the superfluous formatting the translator sees lots of tags inbetween letters of words, which makes for slower translation and a complaining translator!

Some formatting is obviously left as is, so when the idml file is downloaded all the text is translated with major formatting remaining so there is very little tidying up to do.

The formatting we are changing is usually only used to fit the source text by the designer and is irrelevant to us as the target text is normally about 20-30% longer.

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