Overview

In our previous blog (March 9, 2015) we introduced the concept of using a script to create animation for InDesign fixed layout projects. To animate a page item onto the page, we developed two handlers (subroutines):

  • calculateRelativeMove – calculates distance object will move from off page to current position
    parameters:reference to object to move, side of page indicated by “top”, “left”, “bottom”, or “right”
  • toCurrentLocation – sets animation properties for object to move object to current location on page using path points
    parameters: reference to object, duration (in seconds), distance to travel (calculated from calculateRelativeMove), numTimes (number of times to repeat)

In this installation, we will add three more handlers to our script for setting animation properties:

  • setScaleProps – sets scale (scale X array, scale Y array) for creating a Grow or Shrink animation
  • setRotateProps – sets rotation array values for rotating referenced object
  • setOpacityProps – sets opacity array values for controlling visibility

Scale

InDesign allows an object to be scaled horizontally and/or vertically. This is controlled by two properties in the object’s animation settings object: scale x array and scale y array.

Each of these arrays (lists) allows for one or more arrays to indicate the relative size of the object at any point in time. This gives your script a lot of power. Here is how it works:
Each list inside the scale x array or scale y array, is a list of two values:
timeline indicator – expressed as a time frame with a rate of 24 frames per second
relative size – expressed as a percentage of original size

For a one second animation it will need to have a time frame value of 23 (counting from 0).

Exercise

To see how this works, create a circle anywhere in an empty InDesign document that has been created for Digital Publishing intent. Fill it with any color. With the object selected, run the following:

   tell application "Adobe InDesign CC 2014"
	set selList to selection
	set objRef to item 1 of selList
	set uScale to {{0, 100.0}, {23, 200.0}} --time frame, scale
	set dTime to 1.0 --duration
	set numTimes to 1
	my setScaleProps(objRef, uScale, uScale, dTime, numTimes)
   end tell
   (*Scales object given horizontal and vertical lists, duration, and repeat*)
   on setScaleProps(objRef, scaleX, scaleY, dTime, numTimes)
	tell application "Adobe InDesign CC 2014"
	   tell animation settings of objRef
		set duration to dTime
		set scale x array to scaleX
		set scale y array to scaleY
		set plays to numTimes
	   end tell
	end tell
   end setScaleProps 

View the animation in the EPUB Interactivity Preview (Option + Shift + Return).

Other values you may use frequently for time frames are as follows: 47 = 2 seconds, 71 = 3 seconds, 95 = 4 seconds, 119 = 5 seconds, 143 = 6 seconds

Exercise 2

Now change the values for uScale and dTime in the script above to read as follows:

   set uScale to {{0, 100.0}, {23, 200.0}, {47, 100}}
   set dTime to 2.0

Notice that this scale list indicates the animation has a 2 second timeline (value of 47). If the duration (dTime) is not set accordingly (2 seconds), the script will error. Also, notice in the handler that duration is set first (before the scale x and/or scale y array).

Now change the value for numTimes to 3.

Exercise 3

Instead of using the same value for both horizontal and vertical scale, you might want to have non-uniform scaling. For this change the top portion of the script to read:

   tell application "Adobe InDesign CC 2014"
      set selList to selection
      set objRef to item 1 of selList
      set hScale to {{0, 100.0}, {23, 200.0}, {47, 100.0}}
      set vScale to {{0, 100.0}, {47, 50.0}}
      set dTime to 2.0
      set numTimes to 3
      my setScaleProps (objRef, hScale, vScale, dTime, numTimes)
   end tell

With the object selected, run the script and view the animation in the EPUB Interactivity Preview. Experiment with different settings until you are comfortable using scaling.

Rotation

The rotation array property for an object’s animation settings works similar to that of scale. The property is a list (an array) having one or more 2-item lists indicating a timeline value and amount of rotation.

Exercise 4

To see how this works, create a triangle anywhere on the page and fill it with a color. With the triangle selected, run the following script.

   tell application "Adobe InDesign CC 2014"
	set selList to selection
	set objRef to item 1 of selList
	set rArray to {{0, 0.0}, {23, 180.0}}
	set dTime to 1.0
	set numTimes to 3
	my setRotateProps(objRef, rArray, dTime, numTimes)
   end tell
   (*Rotates object given rotation array, duration, and repeat*)
   on setRotateProps(objRef, rArray, dTime, numTimes)
	tell application "Adobe InDesign CC 2014"
	   tell animation settings of objRef
		set duration to dTime
		set rotation array to rArray
		set plays to numTimes
	   end tell
	end tell
   end setRotateProps 

View the animation in the EPUB Interactivity Preview panel.

Opacity

There is a third property for an object’s animation settings that works similar to that of scale and rotation. It is opacity. It also takes a lists of lists where each item in the list indicates a time frame value and the amount of opacity. Opacity is a value from 0 to 100. For opacity, your script may want to set one other property: ease type. Although easing is more often used for other animations such as a fly in, it also can control whether the object fades in or just appears all at once. For most opacity animations you can just let InDesign decide how to set up the opacity list (array). For this the handler listed below can accept a value of true or false. If true, the ease in array is created automatically using the begin and end time frames for calculation.

Exercise 5

To test this out, create a text frame with some text (“Hello World”) set in a bold, large font. With the text frame selected, run the following:

   tell application "Adobe InDesign CC 2014"
	set selList to selection
	set objRef to item 1 of selList
	set oArray to {{0, 0.0}, {47, 100.0}}
	set dTime to 2.0
	set doEase to true
	my setOpacityProps(objRef, oArray, dTime, doEase)
   end tell
   on setOpacityProps(objRef, oArray, dTime, doEase)
	tell application "Adobe InDesign CC 2014"
	   tell animation settings of objRef
		set duration to dTime
		set opacity array to oArray
		if doEase is false then
		   set ease type to no ease
		end if
	   end tell
	end tell
   end setOpacityProps

View the animation in the EPUB Interactity Preview panel.

To see how the ease was calculated, run the following with the same object selected:

   tell application "Adobe InDesign CC 2014"
	set selList to selection
	set objRef to item 1 of selList
	set testIt to opacity array of animation settings of objRef
   end tell 

If you want total control over the opacity of the object, you can set a value for each time frame of the animation. For this you will want to set doEase to false.

In the script above, set the oArray statement as follows:

   set oArray to {{0, 0.0}, {1, 0.0},{2, 0.0},{3, 50.0},{4, 60.0},{5, 70.0},{6, 80.0},{7, 90.0}, {8,100.0}, {11, 100.0}, {23, 100.0}}
   set doEase to false
   set dTime to 1.0 

Challenge Project 1

After you have completed the exercises above, this challenge should be a cinch. Create a colorful heart on the first page of a document created for Digital Publishing intent. Have the heart grow by 50% (scale will be 150%) and then return to original size (100%). Repeat the animation several times. Then have a message appear gradually over the heart. Hint: since the script will be working with more than one object, you will want to give each of the objects a name. You can then refer to the object as text frame “nameHere”. How you refer to the heart in the script, will depend on how it is created. If you draw it freehand using the pen tool, the script can refer to it as polygon “Heart” (if that is what you named it). If you import an image, you can reference its containing rectangle for the animation.

Transform Offsets

For scale and rotate, there is one other property that you will want to add to the object’s animation settings. This is transform offsets. This property dictates the “pin” point from which the object will be rotated or scaled. The value is a single array of two values indicating the relative horizontal and vertical position of the “pin” point within the item’s bounding box. This value is expressed as a decimal from 0 to 1 as measured from the top left corner. To indicate the center point both horizontally and vertically, the array would be {0.5, 0.5}. To indicate the bottom right corner, the array would be {1.0, 1.0}. Remember, for all positional arrays the horizontal comes before the vertical.

Exercise 6

Modify the Animate Rotation and Animate Scale scripts above to pass a value for the transform offsets list property to its handler. For the rotation script, the variable for this property could be set as follows:

   set tOffsets to {0.5, 0.0}

The call to the handler would then be

   my setRotateProps (objRef, rArray, dTime, numTimes, tOffsets)

And in the setRotateProps handler, add the following line:

   set transform offsets to tOffsets

Don’t forget to add tOffsets to the parameter list as part of the on setRotateProps handler signature:

   on setRotateProps (objRef, rArray, dTime, numTimes, tOffsets) 

With these changes in place, select the triangle on the page and run the script. View the animation in the EPUB Interactivity Preview panel.

Make the same changes to the scaling script and run the script with the circle selected. View the animation to see the difference the transform offsets setting can make.

Challenge Project 2

Place an image of the world in the center of a document created for Digital Publishing intent. Import an image of an airplane and set the animation to have it fly around the world several times. Hint: The containing rectangle for the airplane will need to be large enough to have its transform offsets set to correspond with the center of the world and still be large enough to accommodate the airplane. (See screenshot below.) For this the transform offsets will be {0.5, 1.0}.

Onward and Upward

Make sure you understand what has been covered to this point and get ready for some fun little projects.