Multiple comps that are windows into a single footage item.

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

Hi All,

I had a good day today and answered my own question.

Here is the code:

Code: Select all

//Gridify comps.
//Takes selected footage item and creates multiple comps that are windows into the footage item.
//Guts from Compify
//Byron Nash, Edited and Improved by Paul Tuersley
//October 2004
//
//Select single footage items to be gridified.

{ //opening brace
	var proj = app.project;//set project

	// create undo group if user didn't cancel dialog
	app.beginUndoGroup("Gridify_Comp");

	var projColl = proj.items;//list of items in project
	writeLn("Grid RECT Comps");
	var myComps = new Array();//array for storing all the comps made
	
	var selItems = app.project.selection;//set selected import items to an array
	if (selItems.length > 0){//check to see if anything is selected
		var myColl = app.project.selection;//if so the use the selection
		var i = 0;
	} else {//if not, use entire project contents
		var myColl = new Array();
		for (j=0; j < projColl.length; j++){//add project list to an array
			myColl[j] = projColl[j+1];
		}
	}
	//Specify your number of comps needed here.
	var gridWidth = 4;
	var gridHeight = 2;
	for (y=0; y < gridHeight; y++) {
		for (x=0; x < gridWidth; x++) {
			var suffix = stillInfo[0];//get suffix from array 
			for (i=0; i <= myColl.length; i++) {//loop through the project
				var curItem = myColl[i];
				if (curItem instanceof FootageItem) {//check for footage items
					var extPos = curItem.name.lastIndexOf(".");//find file extension
					//add suffux to comp name and remove the file extension
					suffix = "(" + x + "x" + y +")";
					var curName = curItem.name.substring(0, extPos) + "_" + suffix;
					//Truncate comp name if it exceeds the 31 character limit
					if (curName.length > 30){
						curName = curName.slice(0,29-suffix.length) + "_" + suffix;
					}
					//setup comp variables
					var curWidth = curItem.width/gridWidth;
					var curHeight = curItem.height/gridHeight;
					var curAspect = curItem.pixelAspect;
					var curDuration = curItem.duration;
					var curRate =  curItem.frameRate;
					if (curDuration == 0){
						curDuration = stillInfo[2] //set duration to dialog value if it is a still image
					}
					if (curRate < 1){
						curRate = stillInfo[1]//set frame rate to dialog value if it is a still image
					}
					//create comp and add layer
					var newComp = projColl.addComp(curName,curWidth,curHeight,curAspect,curDuration,curRate);//make new comp
					var lcoll = newComp.layers;//variable for collection of layer objects in logoComp
					
					//Add layer.
					var curLayer = lcoll.add(curItem);
					//Position it to the appropriate place in the grid.
					myPosition = curLayer.property("position"); 
					//myPosition.setValueAtTime(0,[(curWidth/2)-(x * curWidth),(curHeight/2)-(y * curHeight)]); 
					myPosition.setValueAtTime(0,[(curItem.width/2)-(x * curWidth),(curItem.height/2)-(y * curHeight)]); 
					
					myComps[myComps.length] = newComp;//add comp to array
				}
			}
		}
	}
	writeLn("Created " + myComps.length + " Comps");
	app.endUndoGroup();

}//closing
Compify to the rescue!
I took the guts out of compify and adjusted it as needed.

USAGE:
Select a single footage item and run the script.

OUTPUT:
It will create a series of comps with a single layer (the one you selected) in the comp. The position of the layer is offset so that if you were to render each comp, you would have a window into the original footage item offset by the position in the grid.

ToDo:
Automatically add these new comps to the render que? ( I guess I'll be digging around for code to do that)
"Up And Atom

No...No

Up And At Them!"
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

ToDo:
Automatically add these new comps to the render que? ( I guess I'll be digging around for code to do that)
Here you go.. I also fixed a small typo you had on the 1st var suffix.

-Lloyd

Code: Select all

//Gridify comps.
//Takes selected footage item and creates multiple comps that are windows into the footage item.
//Guts from Compify
//Byron Nash, Edited and Improved by Paul Tuersley
//October 2004
//
//Select single footage items to be gridified.

{ //opening brace
   var proj = app.project;//set project

   // create undo group if user didn't cancel dialog
   app.beginUndoGroup("Gridify_Comp");

   var projColl = proj.items;//list of items in project
   writeLn("Grid RECT Comps");
   var myComps = new Array();//array for storing all the comps made
   
   var selItems = app.project.selection;//set selected import items to an array
   if (selItems.length > 0){//check to see if anything is selected
      var myColl = app.project.selection;//if so the use the selection
      var i = 0;
   } else {//if not, use entire project contents
      var myColl = new Array();
      for (j=0; j < projColl.length; j++){//add project list to an array
         myColl[j] = projColl[j+1];
      }
   }
   //Specify your number of comps needed here.
   var gridWidth = 4;
   var gridHeight = 2;
   for (y=0; y < gridHeight; y++) {
      for (x=0; x < gridWidth; x++) {
         for (i=0; i <= myColl.length; i++) {//loop through the project
            var curItem = myColl[i];
            if (curItem instanceof FootageItem) {//check for footage items
               var extPos = curItem.name.lastIndexOf(".");//find file extension
               //add suffux to comp name and remove the file extension
               var suffix = "(" + x + "x" + y +")";
               var curName = curItem.name.substring(0, extPos) + "_" + suffix;
               //Truncate comp name if it exceeds the 31 character limit
               if (curName.length > 30){
                  curName = curName.slice(0,29-suffix.length) + "_" + suffix;
               }
               //setup comp variables
               var curWidth = curItem.width/gridWidth;
               var curHeight = curItem.height/gridHeight;
               var curAspect = curItem.pixelAspect;
               var curDuration = curItem.duration;
               var curRate =  curItem.frameRate;
               if (curDuration == 0){
                  curDuration = stillInfo[2] //set duration to dialog value if it is a still image
               }
               if (curRate < 1){
                  curRate = stillInfo[1]//set frame rate to dialog value if it is a still image
               }
               //create comp and add layer
               var newComp = projColl.addComp(curName,curWidth,curHeight,curAspect,curDuration,curRate);//make new comp
               var lcoll = newComp.layers;//variable for collection of layer objects in logoComp
               
               //Add layer.
               var curLayer = lcoll.add(curItem);
               //Position it to the appropriate place in the grid.
               myPosition = curLayer.property("position");
               //myPosition.setValueAtTime(0,[(curWidth/2)-(x * curWidth),(curHeight/2)-(y * curHeight)]);
               myPosition.setValueAtTime(0,[(curItem.width/2)-(x * curWidth),(curItem.height/2)-(y * curHeight)]);
			   
			   app.project.renderQueue.items.add(newComp); // add comp to render queue
               
               myComps[myComps.length] = newComp;//add comp to array
            }
         }
      }
   }
   writeLn("Created " + myComps.length + " Comps");
   app.endUndoGroup();

}//closing
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

Lloyd,

Thanks for the add to render que line, that nearly does it. The only thing left is to specify an output module I usually render to quicktime (not the default AVI) and have a few different presets already set up.

Say I have an output module called "QT". Do you know what would be the line of code to specify an output module :?:
"Up And Atom

No...No

Up And At Them!"
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

Found a work around, I simply set my QT output module as the default and all newly added que items use that output module. :lol:
"Up And Atom

No...No

Up And At Them!"
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Code: Select all

//Gridify comps.
//Takes selected footage item and creates multiple comps that are windows into the footage item.
//Guts from Compify
//Byron Nash, Edited and Improved by Paul Tuersley
//October 2004
//
//Select single footage items to be gridified.

{ //opening brace
	
////////////USER VARIABLES///////////////////////////////////////////////////////////////////////////////////////////////////////
			
				var gridWidth = 4;
				var gridHeight = 2;
			
				var myRenderSettings = "Best Settings";//Name of Render Settings Template
				var myOutputModule = "Lossless"; //Name of Output Module Template
				var myPath = "~/Desktop/";  //Path of where you would like your rendered files to be saved, make sure to include a trailing /
				
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
   var proj = app.project;//set project

   // create undo group if user didn't cancel dialog
   app.beginUndoGroup("Gridify_Comp");

   var projColl = proj.items;//list of items in project
   writeLn("Grid RECT Comps");
   var myComps = new Array();//array for storing all the comps made
   
   var selItems = app.project.selection;//set selected import items to an array
   if (selItems.length > 0){//check to see if anything is selected
      var myColl = app.project.selection;//if so the use the selection
      var i = 0;
   } else {//if not, use entire project contents
      var myColl = new Array();
      for (j=0; j < projColl.length; j++){//add project list to an array
         myColl[j] = projColl[j+1];
      }
   }
   //Specify your number of comps needed here.
   for (y=0; y < gridHeight; y++) {
      for (x=0; x < gridWidth; x++) {
         for (i=0; i <= myColl.length; i++) {//loop through the project
            var curItem = myColl[i];
            if (curItem instanceof FootageItem) {//check for footage items
               var extPos = curItem.name.lastIndexOf(".");//find file extension
               //add suffux to comp name and remove the file extension
               var suffix = "(" + x + "x" + y +")";
               var curName = curItem.name.substring(0, extPos) + "_" + suffix;
               //Truncate comp name if it exceeds the 31 character limit
               if (curName.length > 30){
                  curName = curName.slice(0,29-suffix.length) + "_" + suffix;
               }
               //setup comp variables
               var curWidth = curItem.width/gridWidth;
               var curHeight = curItem.height/gridHeight;
               var curAspect = curItem.pixelAspect;
               var curDuration = curItem.duration;
               var curRate =  curItem.frameRate;
               if (curDuration == 0){
                  curDuration = 10 //set duration for a still image
               }
               if (curRate < 1){
                  curRate = 29.97//set frame rate for a still image
               }
               //create comp and add layer
               var newComp = projColl.addComp(curName,curWidth,curHeight,curAspect,curDuration,curRate);//make new comp
               var lcoll = newComp.layers;//variable for collection of layer objects in logoComp
               
               //Add layer.
               var curLayer = lcoll.add(curItem);
               //Position it to the appropriate place in the grid.
               myPosition = curLayer.property("position");
               //myPosition.setValueAtTime(0,[(curWidth/2)-(x * curWidth),(curHeight/2)-(y * curHeight)]);
               myPosition.setValueAtTime(0,[(curItem.width/2)-(x * curWidth),(curItem.height/2)-(y * curHeight)]);
            
				var myRQItem = app.project.renderQueue.items.add(newComp); // add comp to render queue
				
				myRQItem.applyTemplate(myRenderSettings); 
				myRQItem.outputModule(1).applyTemplate(myOutputModule);  
				myRQItem.outputModule(1).file = new File(myPath+curName); 
               
               myComps[myComps.length] = newComp;//add comp to array
            }
         }
      }
   }
   writeLn("Created " + myComps.length + " Comps");
   app.endUndoGroup();

}//closing
Post Reply