Your prescription for increased productivity and profitability
If you have been following along with the previous posts in this series (Animating InDesign with Scripts) you should have a pretty good handle on the basics of writing scripts for animation. For our purpose we have been looking at code that is part of a sample script provided by Adobe for InDesign: AnimationEncyclopedia.applescript. This script is found in the Samples:Applescript folder for InDesign’s Scripts panel. (Yes, the same script written for JavaScript is found in the Samples:Java Script folder.)
Because the previous scripting examples have been covering the basics, you may have wondered: “Why bother with a script when everything is built into InDesign?” The bottom line is that basic functionality is built in, but if you want to get really creative, you need to write a script. Besides, for those who write code in their sleep, writing a script makes a lot more sense then working with the user interface. (My opinion.)
This animation creates a single rectangle with a number of property changes over a period of six seconds.
The animation settings for the rectangle created by the script makes sure that the duration for the animation is set before attempting to create keyframes. Yes, that’s keyframes—similar to those you work with in the new Adobe Animate CC 2017 application. If you have worked with that application, the following will be in familiar territory. If not, follow along, it will make sense once you work with it.
If using an animation rate of 24 frames per second (standard), the following number values need to be inscribed in big letters somewhere you won’t forget: 1 second = 23; 2 seconds = 47, 3 seconds = 71, 4 seconds = 95, 5 seconds = 119, 6 seconds = 143. Notice that each of these values is the result of multiplying the number of seconds by 24 and subtracting 1.
What is being introduced with this script is the ability to change rotation, scale, and opacity for a page item for each 1 second interval in the timeline (keyframe). The first value for each animation list item is the keyframe value. For rotation, the list {23, 200} sets the rotation at 200 degrees at 2 seconds.
We have taken the liberty to change the script slightly just to make it a little simpler to follow. Points are being used for measurement units as each point within a motion path is defined using three x/y coordinates measured in points.
tell application "Adobe InDesign CC 2017" set measurement unit of script preferences to points tell document 1 set myRectangle to make rectangle with properties ¬ {name: "myRectangle", geometric bounds:{72, 72, 112, 172}, fill color: swatch 4} end tell --set animation settings for rectangle tell animation settings of myRectangle --set total length for the timeline set duration to 6 set motion path to {{0, {{0, 0}, {0, 0}, {0, 0}}},¬ {23, {{200, 0}, {200, 0}, {200, 0}}}, ¬ {47, {{200, 200}, {200, 200}, {200, 200}}},¬ {119, {{0, 200}, {0, 200}, {0, 200}}}, ¬ {143, {{0, 0}, {0, 0}, {0, 0}}}} --set rotation for each second of the timeline (keyframes) set rotation array to {{0,0}, {23, 200.0}, {47, 100.0},¬ {71, -100}, {95, 0}, {119, 100}, {143, -360}} set scale x array to {{0, 100.0}, {23, 200.0}, {47, 100.0}, ¬ {71, 300.0}, {95, 100.0}, {119, 200.0}, {143, 100.0}} set scale y array to {{0, 100.0}, {23, 0.0}, {47, 100.0}, ¬ {71, 0.0}, {95, 100.0}, {119, 300.0}, {143, 100.0}} set opacity array to {{0, 100.0}, {23, 0.0}, {47, 100.0}, ¬ {71, 0.0}, {95, 100.0}, {119, 0.0}, {143, 100.0}} set plays to 1 set plays loop to false set ease type to no ease set transform offsets to {0.5, 0.5} set design option to from current appearance set initially hidden to false set hidden after to false end tell end tell
Open your AppleScript script editor and paste the script in. Make sure it compiles (unexpected line breaks can cause problems).
Create a single page letter-size document in InDesign. Run the script. You should have a colored rectangle near the upper left corner of the page.
Under InDesign’s Window menu item, select Interactive > Animation. This will open the Animation panel. Clicking the button far left at the bottom of this panel will preview the animation in the EPUB Interactivity Previewer.
Now that you have a script to fiddle with, here are the other values for the animation settings properties set above:
Delete the rectangle on the page and chenge just one animation setting property. Test to see the difference the change makes. You might want to enlarge the EPUB Interactivity Preview panel to see the changes better.
Here are some suggestions:
Set transform offsets to {0, 1}
Change the value for timeframe 71 in the scale x list of lists to {71, 500}
Change the value for timeframe 143 in the scale x list of lists to {143, 400}
…EPUB Interactivity Preview
Above is the EPUB Interactivity Preview after running the script where the value for the x scale array was changed to {143,400}.
Be brave. The worse thing that can happen is that you can get an out of range error. Take some time to experiment. In our next blog we will expand on this script to do some fun animations. Until then, keep making changes to your script and testing until it all makes perfect sense to you.