Add a New Null as a Parent to the Selected Layers

Simple script that add's a new null and sets any selected layers to use the new null as parent:

/***************************************/

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
 {
 app.beginUndoGroup("Add Null");
 
 var selectedLayers = activeItem.selectedLayers;
 
 //Add null
 myNull = activeItem.layers.addNull(activeItem.duration);
 var startTime = 9999;

 //Set selected layers parent to the new null
 for(var i=0; i<selectedLayers.length; i++)
 {
  selectedLayers[i].parent = myNull;
  if(selectedLayers[i].startTime < startTime)
   startTime = selectedLayers[i].startTime;
 }
 
 if(startTime == 9999)
  startTime = 0;
  
 myNull.startTime = startTime;
 
 app.endUndoGroup();
 }

 

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.