Batch Process AE projects

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

Is it possible to open After Effects projects with a script?

I use a script for Photoshop that searches through a selected folder, finds a psd, exports a jpeg, closes the file and then moves onto the next psd. I was hoping to be able to do something similar with AE. What I want to do is open all my projects and switch off the text layers (I have a scene number slate in the main comp), save and close. Any ideas?

Ed
It's not the dog in the fight, it's the fight in the dog that matters.
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

Page 26 of the CS3 Scripting Guide:

Application open() method

app.open()
app.open(file)

Description
Opens a project.
Returns
A new Project object for the specified project, or null if the user cancels the Open dialog box.
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

Appreciate it Lloyd.
It's not the dog in the fight, it's the fight in the dog that matters.
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

I'm currently trying to get After Effects to automatically generate the aerender cmd file. The main problem I'm having is how to get the actual "current project" file path and name, I think I'm messing up on some of the escape characters aswell but I'm not sure.

Any help greatly appreciated.

Here's a section of the code I'm using:

Code: Select all

//Create New txt document
var document = new File("W:/path/ED/renderQueue.txt");
//Variable to hold carriage return character
var carReturn = "\r";

//current project file path
var projPath = app.project.file.fsName;

//Check if document already exists
if(document.exists){   //If it does, append more text to it
   document.open("a");
document.write(carReturn + " \"aerender.exe -project \" + projPath\" -mem_usage 60 120  -v ERRORS_AND_PROGRESS");
   document.close();
   alert("New text was appended");
}else if(!document.exists){   //If it doesn't, create a brand new document and add this text
   document.open("w");
   document.write("c:\r\rcd \"C:\Program Files\Adobe\Adobe After Effects CS5\Support Files\"");
   document.close();
   alert("Brand new document saved.");
}
It's not the dog in the fight, it's the fight in the dog that matters.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I don't use aerender so I don't know exactly what to write, but I'll have a go. One thing I'd suggest is try using writeln() instead of write() as I've had more luck with that than trying to add line returns (it may only be a cross platform issue).

Also, as I don't think you actually want any escaped " on this line, I'm guessing it should be:
document.write(carReturn + "aerender.exe -project " + projPath + " -mem_usage 60 120 -v ERRORS_AND_PROGRESS");
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

Actually managed to get it working. It was pretty close. Now I'm just trying to perfect the "Folder.selectDialogue" so I can choose where to save the aerender.cmd file rather than always having to change the path in the script. Here's what's working so far on the text front:

Code: Select all

//Create New txt document
var document = new File("W:path/ED/renderQueue.txt");
//Variable to hold carriage return character
var carReturn = "\r";

//current project file path
var curProj = app.project;
var projPath = curProj.file.fsName;

//Check if document already exists
if(document.exists){   //If it does, append more text to it
   document.open("a");
document.write(carReturn + "aerender.exe -project \"" + projPath + "\" -mem_usage 60 120  -v ERRORS_AND_PROGRESS");
   document.close();
   alert("New text was appended");
}else if(!document.exists){   //If it doesn't, create a brand new document and add this text
   document.open("w");
   document.write("c:\r\rcd \"C:\\Program Files\\Adobe\\Adobe After Effects CS5\\Support Files\"");
   document.close();
   alert("Brand new document saved.");
}
It's not the dog in the fight, it's the fight in the dog that matters.
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

After I've defined Folder.selecDialog, how do I use that object?

For example, I want to create the new RenderQ.cmd file in the location I've picked:

Code: Select all

var Qlocation = Folder.selectDialog ("Select Render Q Location");

var document = new File([QLocation] HDRenderQueue.cmd);
It's not the dog in the fight, it's the fight in the dog that matters.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Try this:

Code: Select all

{
	var Qlocation = Folder.selectDialog ("Select Render Q Location");
	if (Qlocation != null ) {
		var document = new File(Qlocation.fsName + "/HDRenderQueue.cmd");
		alert(document.fsName);
	}
}
I recommend using lots of alerts to try to figure out what's going on. And write little test scripts like this:

Code: Select all

{	
	var testFile = File.openDialog("Select A File");
	if (testFile != null) {
		alert(testFile.fsName);
	}
	var testFolder = Folder.selectDialog("Select A Folder");	
	if (testFolder != null) {
		alert(testFolder.fsName);
	}
}
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

Thanks Paul that's just what I was looking for. I've been doing little tests like you've suggested on other parts of the script (like opening projects and swithcing off selected layers, adding to render queue, things like that) but I was just having trouble with using the folder object returned with selectDialog.

When I get the script finished I'll post it, maybe it'll be of use to someone. I'm basically switching off scene numbers and some handheld parameters (that were initially requested but SOMEONE decided to change their minds) and submitting the comp to the render queue with HD output settings. While also generating the aerender.cmd file. When the AE script finishes it'll execute the aerender queue. One of the latest "headslap" moments was finding out I need to remove the "autosave" string from the search "*.aep" so getFiles doesn't include them. Always learning.

I think I might do another version of the script and assign a keyboard shortcut (using Keyed Up) to it so that while working in a comp you could just generate the line needed in your queue.

Thanks again

Ed
It's not the dog in the fight, it's the fight in the dog that matters.
Ed Smith
Posts: 19
Joined: October 22nd, 2007, 3:57 am
Location: Dublin, Ireland
Contact:

I realise that Lloyds BG Renderer is probably a better/different way to do this, but since it's a by product of a bigger script I'm writing (and since I'm very rarely in a position to actually contribute anything to this forum) here's my script to add scenes to an aerender file that you specify. It's probably not coded very well and if you hit cancel on the "select render q location" dialogue it throws a li'l error ( to be fixed when i get the time). But I'm happy enough with it, especially when used with KeyEd Up.

Code: Select all

{
   var Qlocation = Folder.selectDialog ("Select Render Q Location");
   if (Qlocation != null ) {
      var document = new File(Qlocation.fsName + "/RenderQueue.cmd");
      {
    if(document.exists){   //If Render Queue already exists, alert
        alert("Render Queue already exists, scene will be added to " + document.fsName +" using your current settings");
 
    }else if(!document.exists){   //If it doesn't, create a brand new aerender queue and alert
        alert("Created New Render Queue " + document.fsName);
  }
}
   
   }

var curProj = app.project;
var projPath = curProj.file.fsName;

var carReturn = "\r";
//Check if Queue already exists
{
    if(document.exists){   //If it does, append more text to it
   document.open("a");
document.write(carReturn + "aerender.exe -project \"" + projPath + "\" -mem_usage 60 120  -v ERRORS_AND_PROGRESS");
   document.close();
    }else if(!document.exists){   //If it doesn't, create a brand new document and add this text
   document.open("w");
   document.write("c:\r\rcd \"C:\\Program Files\\Adobe\\Adobe After Effects CS5\\Support Files\"");
   document.write(carReturn + "aerender.exe -project \"" + projPath + "\" -mem_usage 60 120  -v ERRORS_AND_PROGRESS");
   document.close();
  }
   alert("Added " + curProj.file.name + " to your Render Queue.  You, my friend, are compositing your ass off today!!")
}
}
Thanks a million to Paul for all his help so far.

Ed
It's not the dog in the fight, it's the fight in the dog that matters.
Stranger
Posts: 2
Joined: April 25th, 2011, 4:17 am
Location: Paris, France
Contact:

Just to say that you bright my day! :D
Julien
Post Reply