Friday, December 30, 2005
Height of a Table (continued)
One of the golden rules of scripting is: if you think of an ugly solution to something and you are repelled by just how ugly it is, there probably is an easier solution just waiting to be found. That certainly applies here.
So, now I need to work out which is the last row on each page. That should be easy enough.
First, we need to know which table to work on. Let's require the user to have an insertion point in the table of interest:
1. To get the parent story of the table you need:
2. To find a table in a story, you use the storyOffset property of the table, but this seems to miss by one. My story is only one character long (even though it also has 10 lines) and yet the storyOffset return is 1.
3. Obviously, in this case, to get all the text frames containing the table, I could just get all the text frames of the story because that's all there are, there ain't no more, but of a mind to experiment. And so I tried:
4. So, I tried selecting the character to see what would happen:
5. So I went for:
So, it looks as though the only way to get a list of the text frames is to walk through the table getting the parent text frame of each row and adding any not already on the list to the list. Or, I can use a priori knowledge about the particular table I'm working with and just run with the frames of the story.
Happens, that I'm also going to need to know which is the last frame of each page, so I'm going to have to walk through anyway, so perhaps I'll do that after all.
More to come ...
myStory = app.selection[0].parentStory;Gives me the base of each table section in the ten frames of this particular story (which consists entirely of the table).
myTFs = myStory.textFrames;
myBs = myTFs.everyItem().lines[-1].baseline;
So, now I need to work out which is the last row on each page. That should be easy enough.
First, we need to know which table to work on. Let's require the user to have an insertion point in the table of interest:
var ErrMsg = "Please select a table.";Next, we need to gather some data: how many frames are part of the table? That raises the question does a table have a parentTextFrames property -- answer: No! What about the "character" holding the table? Let's experiment:
if (app.selection.length == 0) { errorExit(ErrMsg) }
var myTable = app.selection[0];
while (myTable.constructor.name != "Table") {
myTable = myTable.parent;
if (myTable.constructor.name == "Application") { errorExit(ErrMsg) }
}
1. To get the parent story of the table you need:
myTable.parent.parentStorybecause the parent is the first text frame (note that if the table is nested inside another, the parent is a cell of that other table, but I'm not going to worry about that right now).
2. To find a table in a story, you use the storyOffset property of the table, but this seems to miss by one. My story is only one character long (even though it also has 10 lines) and yet the storyOffset return is 1.
3. Obviously, in this case, to get all the text frames containing the table, I could just get all the text frames of the story because that's all there are, there ain't no more, but of a mind to experiment. And so I tried:
myChar = myTable.parent.parentStory.characters[myTable.storyOffset - 1];but all I got was the one text frame.
myTFs = myChar.parentTextFrames;
4. So, I tried selecting the character to see what would happen:
app.select(myChar);and again, all I got was the one text frame. But then I noticed something interesting. Only the first part of the table was selected, so indeed a singular text frame was all I'd expect.
myTFs = app.selection[0].parentTextFrames;
5. So I went for:
app.select(myChar.parentStory.texts[0]);and even though this did select the whole length of the table, I still only got the first text frame returned (actually, that's an assumption; let's just say I only got one text frame).
myTFs = app.selection[0].parentTextFrames;
So, it looks as though the only way to get a list of the text frames is to walk through the table getting the parent text frame of each row and adding any not already on the list to the list. Or, I can use a priori knowledge about the particular table I'm working with and just run with the frames of the story.
Happens, that I'm also going to need to know which is the last frame of each page, so I'm going to have to walk through anyway, so perhaps I'll do that after all.
More to come ...