Automating Adobe InDesign CC


Animating Adobe Fixed Layout EPub

Monday, April 06, 2015

It's All About Time (Timing)

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.

Timing Settings

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).

Looking At Timing Settings

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.

AppleScript editor showing 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.

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:

  • plays loop - whether the animation should loop (true or false)
  • plays - the number of times the animation will play
  • placement - the group's position within the timing list

Also, like the timing list, a timing group can contain one or more elements. These are its timing targets.

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.

Add Timing Group

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.

Animate Two Objects Together

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.

  • First, we need to destroy the existing timing list and create a new one.
  • Next, we will create a timing group for the first object.

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.

Animate With Grouping

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.

  1. Group the two page items
  2. In the script, establish a reference to the group as an element of its parent spread. There are now three page items, the two individual page items, and the group.
  3. Inside the tell pageRef block, add the following:
       set item3 to group 1 
    (This reference can be used since there is only 1 group on the page.)
  4. Establish animation settings for the group to move it a given distance from its current position.
  5. Change the statements directed to timing list 1 to establish the group as the dynamic target for its first timing group.
  6. Add the two page items to this timing group.

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 the modified Nested Timing Target script
Page items after running modified Nested Timing Target script

    Experiment with the values set for the following:
  • dTravel for groupRef animation (dTravel)
  • duration for groupRef animation (dTime)
  • delay seconds
  • plays value for tGroup1
  • delay seconds for timing targets in tGroup1

Challenge:

Use the toCurrentLocation handler developed in the previous blog (March 31) to allow the page items to travel along a jagged path.

Trackback Link
http://www.yourscriptdoctor.com/BlogRetrieve.aspx?BlogID=16932&PostID=1402794&A=Trackback
Trackbacks
Post has no trackbacks.

Recent Posts


Tags

ePub text New Web HTML5 Enabling Groups InDesign Presentations page breaks CSS Buttons AppleScript Placeholder text Export for InCopy object styles InCopy/InDesign Workflow images Fixed Format ePub find asset Document Presets CSS Regions resizing images InDesign library assets giving up after Footnotes Custom CSS Style Sheets Check for Styles InDesign assets Fixed Format Automated InCopy Workflow lists ePub styling EPUB3 Export InDesign CC Image Placement InDesign Libraries Export to SWF ePub ePub for Kindle Create Text Frame table styles Animating Page items automation Styling Columns import text stylesheets Document stylesheets Motion Presets Adobe InCopy CC alternate text Typekit Document from Template rotating objects Metadata date objects ePub for iPad Text Cleanup with timeout Creative Cloud Script to Massage Text Templates Rollover Multi-state objects Export HTML Animated Text automating InDesign Auto Reverse on Roll Off Text Variables Keyboard Shortcuts motion path points Placing images HTML Export AppleScript dialogs InCopy CC do script ExtendScript timing settings text placement Custom Style Sheets timing groups Adobe InDesign CC Caption Variable AppleScript Templates Find Object Float Epub Footnotes Tables Edge Code motion path Tips and Tricks InCopy text import InCopy Workflow document information Adding Captions automated workflow Automating animations Custom Dialog CSS Shapes Article panel Clip-Path Create Document HTML Hyperlinks paragraph styles ePub content PDF new document CSS3 Shapes ePub export Adobe InCopy ePub Images styles InDesign template Animation Behaviors InCopy template Custom Buttons Fixed Layout ePub scripting Rounded Corners Photoshop Photoshop info timing lists Workflow automation recursion say image metadata

Archive