Take a Walk on the Timeline
July 06, 2009 | Snippets | en | fr
When he was working on the terrific Ibsen's “Brand” eBook, Klaus Nordby asked me for a little gadget to finish off the building of his work. He needed a “page-timeline-indicator” graphic at the bottom, which visualizes the exact place the reader is currently reading. So what the book designer wanted for Christmas (or before!) was a neat InDesign script which automatically calculates such a timeline walker and shows the input. Let us see how Klaus' prayer has been answered...
In the layout designed by Klaus, the page-timeline-indicator appears as a small slide running from page to page, by tiny increments. The animation below shows the first steps. In the full PDF, the process begins at page 1, ends at page 430, so there are 430 instances of the page item. Do you picture yourself pasting and placing by hand the same object 430 times?
The power of scripting is to convert this kind of exhausting task into a simple click. Sometimes a long development is required, but this time the solution was almost obvious: the user only needs to create and position the object on the first page it shows up (initial position), and to duplicate it to the last place it shows up (final position), on the same page. Then he selects the first and the second page item, and runs the script.
Regarding the script, we ask the user for the number of pages the object will cross. Our job is only to calculate the perfect move to apply from one page to the next, for the object to reach the expected position when instancied on the last page.
Here is the pseudo-code for the script:
var objs = [ app.selection[0] , app.selection[1] ]; // objs[0] reflects the object at its initial state // objs[1] reflects the final state and need to // be removed from the current page var b0 = objs[0].geometricBounds; // position of obj0 var b1 = objs[1].geometricBounds; // position of obj1 var d = [ b1[1]-b0[1] , b1[0] - b0[0] ]; var pg0 = app.activeWindow.activePage; var pgs = app.activeDocument.pages; var p1 = ... /*here we will ask the user for the last page*/; var p0 = pg0.documentOffset; var n = p1 - p0; // how many steps? var dx = d[0] / n; var dy = d[1] / n; for ( var i = 1 ; i <= n ; i++ ) { objs[0].duplicate(pgs[p0+i] , [i*dx,i*dy]); } objs[1].remove();
Comments
Amusant et graphique. Je vais te l'emprunter un de ces quatre…
I'm happy to see the page-walker (as I now call it for shorts) is alive and well, Marc! I used it again recently when I designed the PDF manual for the 3D-Coat application (http://www.3d-coat.com/download.htm...). Thanks again for your super work!
Hi Klaus,
Thanks for the link. Gorgeous design!
@+
Marc