Monday, January 21, 2013

cdRenderCompsWithSelected

0 comments
So I wrote an after effects script. I've never written in java, but always fun learning something new.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/*
This script takes the selected footage in an after effects project 
and makes a composition for each footage with the selected layers.
It then adds it to the render queue with the inputed after effects
template and the user specified path.

Input:
 Selected Footage and Layer with an active composition

Returns:
 None

Functions:
 cdGetItems();
 cdRenderCompsWithSelected(comp, layers, footage, outputPathName, endTime, templateName);
*/


function cdGetItems()
{
 var mySelectedItems = [];

 for (var i = 1; i <= app.project.numItems; i++)
     {
         if (app.project.item(i).selected)
             {
                 mySelectedItems[mySelectedItems.length] = app.project.item(i);
             }
     }

 if(mySelectedItems.length < 1)
  {
   alert("You have no footage selected");
   return;
  }
  
 if(app.project.activeItem == undefined || app.project.activeItem == null || app.project.activeItem.selectedLayers == undefined || app.project.activeItem.selectedLayers == undefined || app.project.activeItem.selectedLayers == null || app.project.activeItem.selectedLayers.length == 0)
  {
   alert("You have no adjustment layer selected");
   return;
  }

 else
  {
   var currentComp = app.project.activeItem;
            var selectedLayer = app.project.activeItem.selectedLayers[0];
            var endTime = app.project.activeItem.workAreaDuration;

      var myOutputPath= Folder.selectDialog("Select output path!");      
      if (myOutputPath == undefined)
       {
        return;
       }

      var outputPathName = myOutputPath.fsName + "/";

   var name = prompt("What is your render queue template name?", "Spiderman");
      
      if (name == undefined)
       {
        return;
       }

   cdRenderCompsWithSelected(currentComp, selectedLayer, mySelectedItems, outputPathName, endTime, name)
  }
}

function cdRenderCompsWithSelected(comp, layers, footage, outputPathName, endTime, templateName)
{
    app.beginUndoGroup("Run the Function.");
    var g = 0;
    
    for (var i = 0; i < footage.length; i++)
        {
            var currentFootage = footage[i];
            var myComp = app.project.items.addComp(currentFootage.name, 1280, 720, 1, currentFootage.duration, 24);                           
            var myLayer = myComp.layers.add(currentFootage);
            newLayer = layers.copyToComp(myComp);
            myComp.layers[1].outPoint = currentFootage.duration;
            var theRender = app.project.renderQueue.items.add(myComp);
            var newFile = new File(outputPathName + currentFootage.name);
            theRender.outputModules[1].file = newFile;     

            try
             {
              theRender.outputModules[1].applyTemplate(templateName);
             }
             
         catch(err)
          {
     if (g == 0)
     {
      g = 1;
      alert("You didn't specify an existing template name!");                            
     }
     continue;
          }
        }
    app.endUndoGroup();
}

cdGetItems();