Friday, December 30, 2005

 

Height of a Table

I have this ten-page table that looks a bit of a mess because each page is a different height. The question is: how to automatically adjust the table so each page (except perhaps the last) is the same height?

Were I doing this manually, I'd estimate how much space I had to fill at the bottom of each page and distribute that amount into the bottom inset of each row on the page. So how do I do this in a script? The first thing I checked was that the height return for myTable.height is indeed the complete height of the table:
myTable = app.selection[0].parent.parent;
alert(myTable.height.toPrecision(4));
And that returns 558.7. Hmm. I should add the measurement units into my alert:
//DESCRIPTION: Height of Table 
// Assumes insertion point in text in a cell
myTable = app.selection[0].parent.parent;
alert(myTable.height.toPrecision(4) + " " + decypherUnits(app.activeDocument.viewPreferences.verticalMeasurementUnits));

function decypherUnits (theNum) {
  if (theNum<257) {
    // Custom settings are in points.
    return "pts";
  }
  // Decyphers for print purposes, so inches and inches decimal are both returned as 'ins'
  theNums = [2054187363,2054188905,2053729891,2053729892,2053991795,2053336435,2053335395]
  theMeanings = ["picas","pts","ins","ins","mms","cms","ciceros"]
  for (var i = 0; theNums.length > i; i++) {
    if (theNum == theNums[i])
      return theMeanings[i];
  }
  return theNum
}
And that returned 558.7 picas.

In passing, I notice that this is a function I lifted from an old script. I rarely, these days, take advantage of the JavaScript facility whereby an if statement when true will execute the next statement only without the need to use brackets. While it saves a bit of typing, it creates an unbalanced look that can deceive me if I come back and try to edit the script.

More to come ...

Comments: Post a Comment

<< Home

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