Page 1 of 1

Render to still using layername as filename

Posted: November 13th, 2007, 8:17 pm
by freakdesign
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.");
	}else{
		
		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: ' + currentLayer.name + ' : ' + xstarttime);	

					// add the frames to the render queue
					
					app.project.renderQueue.items.add(activeItem);
					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() + "/" + currentLayer.name + "_([#]) .tga");
				
		}
	}
 }


renderstillstofiles()

Posted: November 14th, 2007, 1:37 am
by Paul Tuersley
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() + "/" + currentLayer.name + "_([#]).tga");
to this
OutputMO.file = new File(Location.toString() + "/" + currentLayer.name + ".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
app.project.renderQueue.render();
OutputMO.file.rename(currentLayer.name + ".tga");

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

Paul

Posted: November 14th, 2007, 6:05 pm
by nab
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 + "/" + currentLayer.name + ".tga");

Posted: December 2nd, 2007, 2:10 am
by freakdesign
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 + "/" + currentLayer.name + ".tga");
The .rename may just do the trick. I will give it a test out and see what happens...

Posted: December 6th, 2007, 4:02 pm
by Darkmoon_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:
http://www.aenhancers.com/viewtopic.php?t=522

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...