• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

looking for a save as Targa script

Community Beginner ,
Nov 06, 2017 Nov 06, 2017

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

TOPICS
Actions and scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 06, 2017 Nov 06, 2017

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=

...

Votes

Translate

Translate
Adobe
Guide ,
Nov 06, 2017 Nov 06, 2017

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);

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2017 Nov 06, 2017

Copy link to clipboard

Copied

LATEST

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;

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines