home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Rotate and Size.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  4.3 KB  |  125 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // Rotate and Size.js
  19. //
  20. // DESCRIPTION
  21. //
  22. // This script demonstrates the use of stopwatches with timeline.
  23. // Switch to Preview mode to watch the object rotate
  24. // and change size at the same time.
  25. //
  26. // HOW TO USE
  27. //
  28. // Create any object and select it in the Composition.
  29. // Select Automation > Run Automation Script > Rotate And Size.js
  30. // Click on Preview Mode to view the object resize and rotate.
  31. //
  32. //////////////////////////////////////////////////
  33.  
  34. // Main Code [Execution of script begins from here]
  35. // Check if any composition is open
  36. if(application.compositions.length > 0){
  37.     comp = application.currentComposition;
  38.     if(comp.selection.length >= 1){ // Checks if at least one object is selected
  39.         targets = comp.selection;// Assigns the current selection to targets
  40.         
  41.         application.currentComposition.saveSelection(); // saves the current selection
  42.         
  43.         // Call function rotateAndSize
  44.         rotateAndSize(targets, 24, 3, 2, 300, 225, 10); 
  45.         // Make changes in the parameters here to change the behavior of this function.
  46.         
  47.         application.currentComposition.restoreSelection(); // restores the saved selection
  48.     }
  49.     else{ // If no objects are selected brings the Console window up 
  50.         Console.show();
  51.         // Writes to the Console
  52.         Console.write("Please select the objects to apply the Animation and run the script again.\n");
  53.     }
  54. }
  55. else{// if no composition open
  56.     // opens a new composition
  57.     comp = application.newComposition();
  58.     Console.show();
  59.     Console.write("New Composition opened\nPlease create and select the objects to apply the Animation and run the script again.\n");
  60. }
  61.  
  62.  
  63. // Add your own functions here
  64.  
  65. //////////////////////////////////////////////////
  66. // rotateAndSize:
  67. // Changes the size and rotates the targets objects
  68. //
  69. // targets: The objects to rotate and change size of
  70. // frames: Total number of frames
  71. // KFR: [KeyFrameRate] Rate at which to place key frames
  72. // stagger: The delay between frames 
  73. // rotation: The angle of rotation
  74. // scale: The end X and Y position of the object
  75. // size: The final size of object
  76. //////////////////////////////////////////////////
  77.  
  78. function rotateAndSize(targets, frames, KFR, stagger, rotation, scale, size)
  79. {
  80.     var oriPosX; //Original X position
  81.     var oriPosY; //Original Y position
  82.     var oriSizeX; //Original X size - width
  83.     var oriSizeY; //Original Y size - height
  84.     var oriAngle; //Original angle of rotation
  85.     var frame0 = targets[0].currentFrame; // First object is current frame
  86.     
  87.     for(var i=0 ; i < targets.length ; i++){    
  88.         // Store original values before starting stopwatch
  89.         oriPosX = targets[i].position.x;
  90.         oriPosY = targets[i].position.y;
  91.         oriSizeX = targets[i].size.x;
  92.         oriSizeY = targets[i].size.y;
  93.         oriAngle = targets[i].rotation;
  94.         
  95.         // Check and start the stopwatches for rotation, size and position 
  96.         if(rotation != oriAngle)
  97.             targets[i].stopwatch.rotation = true; 
  98.         if(size != 200)
  99.             targets[i].stopwatch.size = true; 
  100.         if(scale != targets[i].position.x || scale != targets[i].position.y)
  101.             targets[i].stopwatch.position = true; 
  102.         
  103.         
  104.         //    Note: The initial positions are not stored by turning on the stopwatch.
  105.         //    The stopwatch only records changes AFTER it's been turned on.
  106.         
  107.     
  108.         targets[0].currentFrame = frame0 + ( i * stagger );
  109.         targets[i].rotation = oriAngle;
  110.         targets[i].position.x = oriPosX;
  111.         targets[i].position.y = oriPosY;
  112.         targets[i].size.x = oriSizeX;
  113.         targets[i].size.y = oriSizeY;
  114.  
  115.         // final frame
  116.         targets[i].currentFrame = frame0 + frames + (i * stagger);
  117.         targets[i].rotation = rotation;
  118.         targets[i].position.x = scale ;
  119.         targets[i].position.y = scale;
  120.         targets[i].size.x = size;
  121.         targets[i].size.y = size;
  122.     }
  123. }
  124.  
  125.