Friday, November 04, 2005


Fixing a Numbered List

I make most of my numbered lists myself using nested styles and hanging indents (and, where appropriate, right-aligned tabs to allow for 10).

But one particular list that crops up in the job I'm working on at the moment has as its numbers an inline group. Within each group is an image (of a shadowed circle created in Photoshop) and two text frames, each holding the number, one in white and one in black-- they're slightly offset from each other so the black number forms a shadow of the white one.

During a correction cycle, my client changed one of the lists, deleting one of the numbers. The thought of using find/replace to fix the list up crossed my mind, but it really would have been tedious. So, instead, I banged out this quick and dirty script. Fortunately, each of these lists is segregated into a separate story, so I didn't have to worry about restarting the list for any reason. Here's the script:
//DESCRIPTION: Q&D script to fix numbering in BCS list

Object.prototype.isInArray = function(myArray){
 for (var i=0; myArray.length > i; i++) {
  if(myArray[i] == this){
   return true;
 return false;

var myStory = app.selection[0].parentStory;
var myParaStyles = myStory.paragraphs.everyItem().appliedParagraphStyle;
var myListStyleNames = ["BasicSkillNL","BasicSkillNLkeep"]
var myCounter = 1;
var myPlim = myParaStyles.length;
for (var j = 0; myPlim > j; j++) {
 if (myParaStyles[j].name.isInArray(myListStyleNames)) {
  fixNumbers(myStory, j, myCounter);


// +++++++ Functions Start Here +++++++++++++++++++++++

function fixNumbers(story,paraindex,counter) {
 var myGroup = story.paragraphs[paraindex].groups[0];
 var myTFs = myGroup.textFrames;
 var myLim = myTFs.length
 for (var k = 0; myLim > k; k++) {
  myTFs[k].parentStory.contents = String(counter);
It simply cycles through all the paragraphs of the story looking for list members (there are two eligible styles) using myCounter to hold the current state of the list counter. Worked like a charm and probably took no longer to write than doing the job by hand would have required.

The exit() isn't strictly necessary, but I include it for debugging purposes. I can put a breakpoint next to it so that when I'm testing the script (in its final form and at intermediate stages) I can use ESTK's data browser to view the states of the variables the script sets up.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?