Custom Animations

With Adobe InDesign CC 2014 you have a number of options for creating animations in a fixed layout ePub. This includes InDesign’s built-in motion presets and import for HTML. If you want something a little more than what is offered with motion presets, but you don’t want to go to the trouble of using an application such as Edge Animate to create your animation, you can create your own custom animations right inside of InDesign with a little knowledge of AppleScript or ExtendScript.

In this blog we will explore some simple animations using AppleScript. ExtendScript users can follow along as the process is pretty much the same.

Animation Settings

To get familiar with the settings required for animation, you might want to start with a motion preset or two.

Create a document having measurements set to points. Add a page item all by itself on a page. Manually assign it an animation preset with the options you want to test (see our blog for October 28). Select the object and run the following script:

   tell application "Adobe InDesign CC 2014"
      set selRef to item 1 of selection
      set test to properties of animation settings of selRef
   end tell

When you run the script, the result panel will reveal the values for the following properties:

  • design option: current location
  • has custom settings: can be true or false
  • duration: value in seconds
  • ease type: no ease, ease in, ease out, east in out, or custom ease
  • hidden after: true or false
  • opacity array:  array of arrays
  • plays loop: true or false
  • motion path: list of lists of lists
  • motion path points: list of lists of lists
  • rotation array: list of list
  • scale x array: list of list of lists; will be {{100, 0}} if no change in x value
  • scale y array: list of list of lists; will be {{0,100}} if no change in y value
  • transform offsets: list representing x and y transform as percentage
  • preset: reference to motion preset
  • initially hidden: true or false

To write a script just to replicate this animation would be a lot of unnecessary work. But just for testing, add the values returned from your script above to the Test Animation script below. Run the script just to see how a script would create the same animation. Of course you will need your own values derived from your test script above.

Test Animation

   global mPathPoints 
   --motion path can be global since value will not change
   set mPathPoints to {{{{72, 100}, {72, 100}, {72, 100}}, 
{{500, 100}, {500, 100}, {500, 100}}}, true} 
   tell application "Adobe InDesign CC 2014"
        set selRef to item 1 of selection
	set animSettings to animation settings of selRef
	tell animSettings
		set duration to 1
		set design option to from current appearance
		set ease type to no ease
		set hidden after to false
		set opacity array to {{0, 100.0}, {23, 100.0}}
		set plays loop to false
		set plays to 1
		set motion path points to mPathPoints
		set rotation array to {{0, 0.0}}
		set scale x array to {{0, 100}, {23, 250.0}}
		set scale y array to {{0, 100.0}, {23, 250.0}}
		set transform offsets to {0.5, 0.5}
		set initially hidden to false
	end tell
   end tell

When you run the script, the designated path for the object (green dotted line) is added to the page. The path disappears from view when the object is not selected. You can preview the animation in the EPUB Interactivity Preview panel (Option + Shift + Return).

Understanding Point Lists

The motion path list and the motion path points lists are similar. Both are an array of arrays describing the path that the target item will follow during the animation. Each point in the array is a bezier point value comprising of three arrays, the x and y values for each of the following:

  • the anchor point
  • the left direction control
  • the right direction control

The motion path allows you to set the keyframe value for each point within the path. The motion path points list allows you to determine if the path will be open (the true value that is the last value in the list). Until you understand keyframes, it may be best to stick with motion path points.

When you draw a curve in InDesign (or other vector drawing application), the point through which the curve passes is the anchor point. You can then modify the curve by manipulating the two control points to the left and right of the anchor point (the left direction control and right direction control).

If there is no curve to the point only one array of two values is returned (the anchor point). With a little bit of modification to the path points list returned, you can have a script that replicates your motion path. Sound Difficult? It’s really easy if you let InDesign do the work for you.

Try It

Start with a new page item on a clean page. Using the pen tool, start from the center point of your page item to draw your path. For starters, try creating a path where there are no curves to the points (just click with the pen tool at each point of the path).

With the path you just created selected, run the following script:

Get Path

   tell application "Adobe InDesign CC 2014"
	set selRef to item 1 of selection
	set path1 to entire path of path 1 of selRef
   end tell

If there are no curves in your path, the value for path1 will look similar to the following:

   {{199, 161}, {282, 364}, {428, 161}}

Notice that each point in the list is a single list of two values (the anchor point). To make this list compatible for your animation script you will need to add an x-y list for a left and right control to each point. Since, for a straight point these will be the same as the anchor, this is a simple process of copy and paste. For example, let’s assume your path was the same as the list above.

After adding the left and right control lists to each of the points, your array would read as follows. (Each point will be a list of three lists each having two values.)

   {{{199, 161},{199, 161},{199, 161}}, 
   {{282, 364},{282, 364},{282, 364}}, 
   {{428, 161},{428, 161},{428, 161}}}

Now add a curly brace to the beginning of the list, and a comma, space, true, and curly brace to the end of the list. The value for mPathPoints in the Test Animation script will now read as follows:

   set mPathPoints to {{{{199, 161}, {199, 161}, {199, 161}}, ¬
   {{282, 364}, {282, 364}, {282, 364}}, ¬
   {{428, 161}, {428, 161}, {428, 161}}}, true}

Run your script with the page item selected. Notice the path added. Preview your animation in the animation preview window.

Second Try

Now try the same test using a simple curved path. Follow the directions above, but this time click and drag your pen at each point to create a simple curve. With the path selected, run the Get Path script. This time the result window will have a list of lists where each list item in the list has three values similar to the example following:

   {{{114.0, 185.937109511579}, {199.0, 161.0}, {284.0, 136.062890488421}}, 
   {{288.0, 136.062890488421}, {330.0, 166.612900478468}, {372.0, 197.162910468516}}, 
   {{458.0, 112.0}, {466.0, 92.0}, {474.0, 72.0}}}

Add the curly brace to the beginning of the list and a comma, space, true, and curly brace to the end. You can remove insignificant decimal places. The value for your mPathPoints variable will look similar to the following:

  set mPathPoints to {{{{114.0, 185.937}, {199.0, 161.0}, {284.0, 136.06}}, ¬
   {{288.0, 136.06}, {330.0, 166.61}, {372.0, 197.16}}, ¬
   {{458.0, 112.0}, {466.0, 92.0}, {474.0, 72.0}}}, true}

Make sure there are three lists for each point in your path. Replace the previous mPathPoints statement in your Test Script with your modified one. Run the script with a page item selected. Preview it in the EPUB Interactivity Preview panel.

Get Creative

Try adding more objects to the page and add animation. Preview your animations. Export to EPUB (Fixed Layout) and view in Adobe Digital Editions (Version 4.0.1). Notice that your animations follow immediately one after the other triggered by the page open event. In our next blog we will get a little more creative and work with timing settings.