Render to still using layername as filename

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Posts: 2
Joined: March 13th, 2006, 10:17 pm
Location: Australia

I needed to be able to keep the existing file name rather than getting lumped with photo_0001, photo_0002, etc so I modded existing scripts (like this one: viewtopic.php?t=144) on this site.

I would like to remove the auto numbering but attempts have eluded me thus far.

Code: Select all

 function renderstillstofiles(){
	var activeItem = app.project.activeItem;
	if (activeItem == null || !(activeItem instanceof CompItem)){
		alert("You need to select some layers first.");
		var selectedLayers = activeItem.selectedLayers;
		app.beginUndoGroup("render stills to files");	

		var rq;
		var rq = app.project.renderQueue.numItems; 
		//$.writeln('rq: ' + rq);	
		var Location = folderGetDialog("Select a destination...");  		
		for (i = 0; i < selectedLayers.length; ++i) {
					currentLayer = selectedLayers[i];			
					// render queue does not seem to be zero based so we need to offset by +1
					var currentrq = rq+i+1;
					// get the start time
					var xstarttime
					xstarttime = currentLayer.startTime
					// output variables to the console window (for debugging)
					//	$.writeln('values: ' + + ' : ' + xstarttime);	

					// add the frames to the render queue
					app.project.renderQueue.item(currentrq).timeSpanStart = xstarttime;
					// value can not be 0 - or so it seems so we use the min value of 0.04
					app.project.renderQueue.item(currentrq).timeSpanDuration = 0.04; 

					OutputMO = app.project.renderQueue.item(currentrq).outputModules[1];
					OutputMO.applyTemplate("Targa File");
					OutputMO.file = new File(Location.toString() + "/" + + "_([#]) .tga");

Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

The script was failing for me on this line, because my comp was set to 24 fps
app.project.renderQueue.item(currentrq).timeSpanDuration = 0.04;
so I changed it to:
app.project.renderQueue.item(currentrq).timeSpanDuration = activeItem.frameDuration;

I thought getting rid of the added frame numbers might be as easy as changing
OutputMO.file = new File(Location.toString() + "/" + + "_([#]).tga");
to this
OutputMO.file = new File(Location.toString() + "/" + + ".tga");
but then AE adds the frame numbers to the end, so you get names such as "Dark Red Solid 1.tga00001"

so I figured I could just render the file, then rename it, so I added
OutputMO.file.rename( + ".tga");

But for some reason it isn't renaming the file. At this point I'm stumped...anyone else?

Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan

Try something like this after rendering the current frame/layer:
var renderedFile = new File(OutputMO.file.fsName.replace("[#]",xstarttime/activeItem.frameDuration));
renderedFile.rename(Location.fsName + "/" + + ".tga");
Posts: 2
Joined: March 13th, 2006, 10:17 pm
Location: Australia

Paul Tuersley wrote: But for some reason it isn't renaming the file. At this point I'm stumped...anyone else?
That is where I started to scratch my head. This is why I added in the single # to stop the numbers getting added the end. Good ideas for cleaning up the existing code to make it more widely usable - cheers.
nab wrote: renderedFile.rename(Location.fsName + "/" + + ".tga");
The .rename may just do the trick. I will give it a test out and see what happens...
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK

I think the reason it is not being renamed by your call to FileObj.rename() is that even after rendering, the OutputModule still holds a reference to a (non existant) file without the numbers on the end.

Having some experence in this, I think After Effects puts the numbers on at a very late stage in the rendering process to make sure that whatever you do, you're not inadvertently overwriting old output. I've previously renamed rendered stills using a call to the command line (PC) with a wildcard for the numbers. You can obviously only do this if you're rendering one frame from a sequence at any one time.

Code: Select all

system.callSystem("cmd /c  ren \""+OModule.file.fsName+"?????\" \""+OModule.file.fsName+"\""); 
Doesn't exactly roll off the tongue does it? Calling system like this is discussed a bit more in this post:

I've never used the File.rename method, though I probably should in the interests of OS independence. Without having tested this myself, I'll speculate that you should make a new file object from the old one, adding the numbers (with respect to leading zeroes) yourself, then try .rename()ing that...
Post Reply