Generate Animated Pointer/Label

This will take a 3-point mask drawn on a layer, add some effects to it, and animate it so the result is a label that animates in.  See below for details:

/************************************************************
To use:
Create a new solid of any color
Select the pen tool and draw three points on the solid:
 The first 2 points should be horizontal
 The 3rd point should be the ending point (what you want to point to)
Run the script
The script will:
 Add a second mask which is the dot for the pointer
 Add a yellow stroke and a drop shadow to the layer
 Animate the masks starting at the first point and ending at the 3rd point
 Add easing to the keyframes
 Set the opacity on the layer to 100
 Change the name of the layer and the solid to "Animated Pointer Layer"
 
You can then:
 Change the color of the stroke
 Change the timing of the keyframes
 Anything else that strikes your fancy
 
***************************************************************/

 

var initialLayer = null;
var activeItem = app.project.activeItem;
if (activeItem == null || !(activeItem instanceof CompItem))
 {
  alert("You need to select a composition before running this script");
 }
else
 {
 var selectedLayers = activeItem.selectedLayers;
 app.beginUndoGroup("Generate animated pointer");
 if (selectedLayers.length > 0 )
  {
   DoWork(selectedLayers[0]);
   
  }
 else
  {
   alert("You must select a layer to add the mask to.");
  }
  app.endUndoGroup();
 }
 
 function DoWork(initialLayer)
 {
  
  if(initialLayer.property("mask").numProperties > 0)
  {
   var initialMask = initialLayer.mask(1);
   
   var point1, point2, point3;
   var vertsArray = initialMask.maskShape.value.vertices;
   if(vertsArray.length == 3)
   {
     point1 = vertsArray[0]; 
     point2 = vertsArray[1];
     point3 = vertsArray[2];
     
     var np1,np2,np3,np4;
     var x = point3[0];
     var y= point3[1];
     var radius = 3;
     
     np1 = new Array([x], [y+radius]);
     np2 = new Array([x-radius], [y]);
     np3 = new Array([x], [y-radius]);
     np4 = new Array([x+radius], [y]);

     newMask = initialLayer.Masks.addProperty("Mask");
     myMaskShape = newMask.property("maskShape");
     myShape = myMaskShape.value;
     myShape.vertices = [np1,np2,np3,np4];
     
     var startTime = initialLayer.inPoint;
     myMaskShape.setValueAtTime(startTime+1, myShape);
     
     var firstMask = initialLayer.mask(1);
     initialMaskShape = firstMask.maskShape;
     iShape = initialMaskShape.value;
     iShape.vertices = [point1,point2,point3];
     initialMaskShape.setValueAtTime(startTime+1,iShape);
     
     var xDiff = point3[0]-point2[0];
     var yDiff = point3[1]-point2[1];
     
     var tp1 = new Array([np1[0]-xDiff],[np1[1]-yDiff]);
     var tp2 = new Array([np2[0]-xDiff],[np2[1]-yDiff]);
     var tp3 = new Array([np3[0]-xDiff],[np3[1]-yDiff]);
     var tp4 = new Array([np4[0]-xDiff],[np4[1]-yDiff]);
     
     var shapeTween = new Shape();
     shapeTween.vertices = [tp1,tp2,tp3,tp4];
     myMaskShape.setValueAtTime(startTime+.5, shapeTween);
     
     iShape.vertices = [point1,point2,point2];
     initialMaskShape.setValueAtTime(startTime+.5,iShape);
     
     xDiff = point2[0]-point1[0];
     yDiff = point2[1]-point1[1];
     
     tp1 = new Array([tp1[0]-xDiff],[tp1[1]-yDiff]);
     tp2 = new Array([tp2[0]-xDiff],[tp2[1]-yDiff]);
     tp3 = new Array([tp3[0]-xDiff],[tp3[1]-yDiff]);
     tp4 = new Array([tp4[0]-xDiff],[tp4[1]-yDiff]); 
     
     shapeTween = new Shape();
     shapeTween.vertices = [tp1,tp2,tp3,tp4];
     
     myMaskShape.setValueAtTime(startTime,shapeTween);
     
     iShape.vertices = [point1,point1,point1];
     initialMaskShape.setValueAtTime(startTime,iShape);
     
     var ease = new KeyframeEase(0, 50);
       initialMaskShape.setTemporalEaseAtKey(1, [ease], [ease]);
     initialMaskShape.setTemporalEaseAtKey(2, [ease], [ease]);
     initialMaskShape.setTemporalEaseAtKey(3, [ease], [ease]); 
     
       myMaskShape.setTemporalEaseAtKey(1, [ease], [ease]);
     myMaskShape.setTemporalEaseAtKey(2, [ease], [ease]);
     myMaskShape.setTemporalEaseAtKey(3, [ease], [ease]);    
 
          
     if(initialLayer("Effects").canAddProperty("Stroke"))
     {
      var stroke = initialLayer("Effects").addProperty("Stroke");
      stroke.allMasks.setValue(1);
      stroke.color.setValue([1,1,0]);
     }
     
     if(initialLayer("Effects").canAddProperty("Drop Shadow"))
     {
      var ds = initialLayer("Effects").addProperty("Drop Shadow");
      ds.distance = 4;
      ds.softness = 3;
     }
     
     initialLayer.property("Opacity").setValue(100);
     initialLayer.source.mainSource.color = [1,1,0];
     initialLayer.name = "Animated Pointer Layer";
     initialLayer.source.name = "Animated Pointer Layer";
   }
  }
  else
  {
   alert("No mask on selected layer.");
  }
 }


 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.