Batch Rendering Script - Changing File Seq No

Mauriceh9 wrote on 4/10/2008, 6:02 AM
I'd like to change the sequence number allocated to the output filename so that it starts from "1" rather than "0". The advantage of this is that it would then tie up with the region index that also starts from "1", and thereby make the audit trail of rendered files back to the regions a little more useful. Keeping having to subtract one is a pain to my brain. It would also be useful if the file sequence number were two digits, so that "1" was written as "01" etc, to make the automatic file sorting get the sequence of files into the right order.

I'm not familiar with the scripting syntax, so would be grateful for a little help from an expert. I'm guessing the needed mod for my first requirement lies somewhere in the following lines of code:

String regionFilename = String.Format("{0}[{1}]{2}",
filename,
regionIndex.ToString(),
renderItem.Extension);

Thanks in advance for any help.

Maurice

Comments

JohnnyRoy wrote on 4/10/2008, 7:09 AM
Good guess on the line of code. ;-) This is the modification to do what you want:


String regionFilename = String.Format("{0}[{1:d2}]{2}",
filename,
(regionIndex + 1),
renderItem.Extension);

The {1:d2} pads with 2 leading zeros. {1:d3} would pad with three (i.e., 001 in case there are more than 99 regions). Also (regionIndex + 1) will add one to the region index.

Alternately you could just start the regionIndex from 1 to begin with:

Change line 89 from:


int regionIndex = 0;

to:

int regionIndex = 1;

It's only used for the filename and not as a counter.

~jr
Mauriceh9 wrote on 4/10/2008, 8:35 AM
Hi jr.

Thanks for that, but the padding with zeros part didn't work. Nor did the first solution to starting the file sequence number from "1". I instead used your second solution i.e. changing the initial value of the Region Index to 1 from zero. I wondered whether the fact that I only gave you a small subset of the code gave you the wrong context. I've included the whole block of code below:

// enumerate through each selected render template
foreach (RenderItem renderItem in selectedTemplates) {
// construct the file name (most of it)
String filename = Path.Combine(outputDirectory,
FixFileName(baseFileName) +
FixFileName(renderItem.Renderer.FileTypeName) +
"_" +
FixFileName(renderItem.Template.Name));

if (RenderMode.Regions == renderMode) {
int regionIndex = 1;
foreach (Sony.Vegas.Region region in myVegas.Project.Regions) {
String regionFilename = String.Format("{0}[{1:d2}]{2}",
filename,
regionIndex.ToString(),
renderItem.Extension);
// Render the region
status = DoRender(regionFilename, renderItem, region.Position, region.Length);
if (RenderStatus.Canceled == status) break;
regionIndex++;
}
} else {
filename += renderItem.Extension;
Timecode renderStart, renderLength;
if (renderMode == RenderMode.Selection) {
renderStart = myVegas.SelectionStart;
renderLength = myVegas.SelectionLength;
} else {
renderStart = new Timecode();
renderLength = myVegas.Project.Length;
}
status = DoRender(filename, renderItem, renderStart, renderLength);
}
if (RenderStatus.Canceled == status) break;
}
}

Thanks for your help. Maurice

P.S. Which language is this script written in? Being an old fart I've only ever written code in procedural rather than object orientated code.
JohnnyRoy wrote on 4/10/2008, 2:43 PM
I'm not sure why the padding didn't work for you. It does for me and is standard formatting syntax. I assumed you were using BatchRender.cs from Vegas Pro 8.0 which is written in C#. The code you posted was definitely C# which is an Object Oriented language.

~jr
jetdv wrote on 4/10/2008, 8:21 PM
String regionFilename = String.Format("{0}[{1:d2}]{2}",

The reason this didn't work for you is that you didn't change everything JohnnyRoy told you to change. You did change the 1:d2 but you're sending it a STRING instead of a NUMBER. JohnnyRoy's is sending a NUMBER (the index number plus 1 - which is also why your index didn't start at 1 instead of 0)
altarvic wrote on 4/10/2008, 8:35 PM
regionIndex.Format("00") is much simplier