Copy link to clipboard
Copied
Anyone could help me script a SAVE AS .TGA file in a folder?
Reason I can't use action is that the tag file needs a new suffix (ex: image_01.tga... image_02.tga... image_03.tga)
I'm saving dozens of Targas everyday. so please please the one who could help me would be my hero for the rest of the year.
in short:
PSD file with layers, ---> save as .tga file with suffix 32 bit.
Thanks a million!
/Dominique
Please give this a try...
...#target photoshop
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
Name = Name.replace(/_$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.tga").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix=
Copy link to clipboard
Copied
Please give this a try...
#target photoshop
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
Name = Name.replace(/_$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.tga").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix= zeroPad(Suffix + 1, 3);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".tga");
saveTarga32(saveFile);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
function saveTarga32(saveFile){
targaSaveOptions = new TargaSaveOptions();
targaSaveOptions.alphaChannels = true;
targaSaveOptions.resolution = TargaBitsPerPixels.THIRTYTWO;
activeDocument.saveAs(File(saveFile), targaSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
You may want to add an if to that script.
if (app.activeDocument.bitsPerChannel==BitsPerChannelType.SIXTEEN) {
alert("TGA does not support 16 bit color!");
return;
}