Page 1 of 1

Altered Save and Increment script

Posted: February 11th, 2009, 4:23 pm
by scribling
I need to alter the save an increment script to update the 8th object from the end.
Example filename: xxxXXX_03x03_c05_v01.aep
I need the "5" updated instead of the "1" at the end.
Also it needs to be 2 digits like the example.
... Tried altering it myself but can't figure it out.

Thanks in advance,
Scribling

Re: Altered Save and Increment script

Posted: February 11th, 2009, 7:25 pm
by Yenaphe
Well you could try something like that:

Code: Select all

My_Altered_Name = myfile.name; //myfile shall be the object containing the pointer to your file

// the char you want to change is the 16th in your name, so you can alter the name to get the first part.

My_First_Part = My_Altered_Name.substr(0,15);

// now we check the number and increment it.

My_New_Number = eval(My_Altered_Name.substr(16,16))+1;

// now we put together the new number with the first part of the filename.

My_New_Filename = My_First_Part + My_New_Number;

(edited some code for clarity)

Re: Altered Save and Increment script

Posted: February 12th, 2009, 11:24 am
by scribling
Here's the script I've been using:

Code: Select all

if (!app.project.file) {
	alert ("This project must be saved before running this script.");
} else {
	var currFile = app.project.file;
	var currFileName = currFile.name;
	var extPos = currFileName.lastIndexOf(".");
	var ext = "";
	
	if (extPos != -1) {
		ext = currFileName.substring(extPos, currFileName.length);
		currFileName = currFileName.substring(0, extPos);
	}
	
	var incrementer = 0;
	if (currFileName.charAt(currFileName.length -4) == "_") {
		//Assume the incrementer has run before if underscore is the fourth character from the end.
		//This is the case for files with 3 digit extensions.
		incrementer = currFileName.substring(currFileName.length - 3, currFileName.length);
		currFileName = currFileName.substring(0, currFileName.length -4);
	}
	
	incrementer++;
	var istring = incrementer + "";
	if( (incrementer / 10) < 1.0) {
		istring = "0" + istring;
	}
	if( (incrementer / 100) < 1.0) {
		istring = "0" + istring;
	}
	
	var newFile = File(currFile.path + "/" + currFileName + "_" + istring + ext);
	//alert(newFile.fsName);
	app.project.save(newFile);
}
How do I get the new code to work with it?