Your prescription for increased productivity and profitability
In this installation for creating animations for InDesign Fixed Layout EPub using a script we will start working with timing settings and timing groups. If you made it up to this point with your gray matter still intact, you can breathe a little easier as this subject is not as hard as you might think.
The timing settings object for a spread controls when animations contained within its page items are executed. The timing settings object is contained by a spread and contains timing lists. If you have created an animation for a page item on a page (consequently on its parent, a spread), the spread should have one timing list. This list, by default, is set to initiate animations when the spread is opened. To test this out, create a new document for digital publishing intent (1024 by 768). Place a page item (rectangle, or polygon) anywhere on the page. Copy and paste the following script to the AppleScript Editor. With the page item selected, click the run button (Command+R) to establish animation settings for the page item.
(*Rotate Selected*) set objName to "pageItem1" tell application "Adobe InDesign CC 2014" set selList to selection set objRef to item 1 of selList set name of objRef to objName set rArray to {{0, 0.0}, {47, 180.0}} set dTime to 2.0 set numTimes to 3 set tOffsets to {0.5, 0.5} my setRotateProps(objRef, rArray, dTime, numTimes, tOffsets) end tell (*Rotates object given rotation array, duration, and repeat*) on setRotateProps(objRef, rArray, dTime, numTimes, tOffsets) tell application "Adobe InDesign CC 2014" tell animation settings of objRef set duration to dTime set rotation array to rArray set plays to numTimes set transform offsets to tOffsets end tell end tell end setRotateProps
View the Animation in InDesign’s EPUB Interactivity Preview panel (option + shift + return).
Now that you have animation settings established for a page item, run the following script to get a count of the timing lists for the spread. If the count is greater than 0, the script will return the properties for the timing list.
(*Get Timing List Properties*) tell application "Adobe InDesign CC 2014" set spreadRef to spread 1 of document 1 tell timing settings of spreadRef set groupCount to count of timing lists if groupCount is greater than 0 then set testIt to properties of timing list 1 end if end tell end tell
View the result in AppleScript Editor’s Result panel.
As you can see from the result, the timing list only has one property that can be set: trigger event. By default this is set to on page load. Optionally, the trigger event targeted to the spread can be set to on page click. If you think that all you would need to do is change the value for the timing list’s trigger event, think again. You first need to delete the existing default on page load timing list and create a new one. You can then set the trigger event for the new timing list to on page click.
But that is not the end of the story. When you delete the original timing list you remove all animations that were associated with it. Animations set for page items are associated to a timing list in groups, or timing groups.
A timing list can contain one or more timing groups. At the end of the Get Timing List Properties script (above), add the groupCount variable to return this value to AppleScript’s Result panel.
With the page item selected, run the modified script. The result should be 1.
A timing group, like the timing list, has a limited number of properties. To see these properties change the following line in your modified Get Timing List Properties script.:
set testIt to properties of timing list 1
to read as follows:
set testIt to properties of timing group 1 of timing list 1
Remove the groupCount variable from the bottom of the script.
When you run this test script, you will see that a timing group has the following properties:
Also, like the timing list, a timing group can contain one or more elements. These are its timing targets.
Timing targets define the objects associated with a given timing group. The timing target can also specify a delay value to be applied to the page item’s animation. When associated with the first item in the group, this delay is relative to the start of the animation for the group. For all other items in the group, this delay is from the start of the previous item’s animation.
To see how this works, create a second page item for your test document. In the Rotate Selected script above, change the value for the variable objName to “pageItem2.” With the second item still selected, run the Rotate Selected script.
When you view the animation in the EPUB Interactive Preview panel, the first page item rotates and then the second.
If you were to test to verify the count of timing groups for timing list 1, you would see that there are now two groups. You can verify this using the following script.
(*Test 2*) tell application "Adobe InDesign CC 2014" set spreadRef to spread 1 of document 1 tell timing settings of spreadRef set groupCount to count of timing groups of timing list 1 end tell end tell
You can probably guess which page item belongs to which timing group, but to test, you can add the following statement to the Test 2 script above.
--directly below the set groupCount statement set tGroup1 to timing group 1 of timing list 1 set testIt to name of dynamic target of timing target 1 of tGroup1
Now that you have some idea of the hierarchal structure of the spread’s timing settings object, its time to put this to work to have some fun with animation.
Instead of having the two page items rotate one after the other, we can restructure the timing settings object to have the two objects rotate together.
Instead of having a second timing group, the script will assign the second page item to be a dynamic target of the first timing group. Here is how it can be written, assuming that both page items are still on the page and named pageItem1 and pageItem2.
(*Nested Timing Target*) tell application "Adobe InDesign CC 2014" set spreadRef to spread 1 of document 1 tell spreadRef set item1 to page item "pageItem1" set item2 to page item "pageItem2" end tell tell timing settings of spreadRef delete timing list 1 make timing list with properties {trigger event:on page click} tell timing list 1 set tGroup1 to make timing group with properties {plays:1, plays loop: false, dynamic target:item1} tell tGroup1 make timing target with properties {dynamic target:item2, delay seconds:0} end tell --tGroup1 end tell --timing list 1 end tell --timing settings end tell --application
Click the Clear Preview button at the bottom of the EPUB Interactivity Preview panel. Next, click on the Play button. Nothing happens. Notice that the Nested Timing Target script sets the trigger event for the timing list to on page click. Now click on the page inside the panel’s window. Both page items should rotate simultaneously.
If you were to want the page items in the example above to move across the page while they are rotating, this can be done with just a few changes.
set item3 to group 1(This reference can be used since there is only 1 group on the page.)
It’s not as difficult as it may seem. Start by copying the Nested Timing Target script to a new script window.
Add the toCurentLocation handler to the bottom of this new script
(*toCurrentLocation handler*) on toCurrentLocation(objRef, dTravel, dTime, numTimes) --default List for straight line path set mPathPoints to {{{{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}}, {{0.0, 0.0}, {0.0, 0.0}, {0, 0.0}}}, true} repeat with i from 1 to 3 set item i of item 2 of item 1 of mPathPoints to dTravel end repeat tell application "Adobe InDesign CC 2014" tell animation settings of objRef set duration to dTime set design option to to current location set motion path points to mPathPoints set plays to numTimes end tell end tell end toCurrentLocation
Change the top of the script to read as follows:
tell application "Adobe InDesign CC 2014" set spreadRef to spread 1 of document 1 tell spreadRef set groupRef to group 1 --this line is new set item1 to page item "pageItem1" of groupRef --this line changes set item2 to page item "pageItem2" of groupRef --this line changes end tell --add animation for group; this section is new set dTravel to {-400, 0.0} --moves left 400 pixels set dTime to 2 --duration in seconds my toCurrentLocation(groupRef, dTravel, dTime, 1) tell timing settings of spreadRef delete timing list 1 make timing list with properties {trigger event:on page click} tell timing list 1 set tGroup1 to make timing group with properties {plays:1, plays loop:false, dynamic target:groupRef} tell tGroup1 make timing target with properties {dynamic target:item1, delay seconds:0}--this is new make timing target with properties {dynamic target:item2, delay seconds:0} end tell --tGroup1 end tell --timing list 1 end tell --timing settings end tell --application
Run the script and view the animation in the EPUB Interactivity Preview panel.
Page items after running modified Nested Timing Target script
Use the toCurrentLocation handler developed in the previous blog (March 31) to allow the page items to travel along a jagged path.