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

Upgraded from CS3 to CS4... Now scripts don't export right.

New Here ,
Jun 17, 2009 Jun 17, 2009

Hello... Do you know why the script below doesn't work correctly in CS4?

This worked so great in CS3.. The problem is now, it only saves the last slice... whereas before, it saved each slice perfectly. Do you have any idea what could fix this? Thank a lot for any help!

function ExportJpg(fileSuffix)

{

try

{

var options = new ExportOptionsSaveForWeb();

var jpgFile = new File( savePath + photoName + fileSuffix );

options.quality = 81;

options.format = SaveDocumentType.JPEG; // Or it'll default to GIF.

docRef.exportDocument(jpgFile, ExportType.SAVEFORWEB, options);

}

catch (e)

{ // display error

alert("Error encountered when saving the image! \r\r" + e);

return; // quit

}

};


function fitImage(newImgSize) {

if (docRef.width > docRef.height) {

docRef.resizeImage(newImgSize, undefined, undefined, ResampleMethod.BICUBIC)

}

if (docRef.width < docRef.height) {

docRef.resizeImage(undefined, newImgSize, undefined, ResampleMethod.BICUBIC)

}

if (docRef.width == docRef.height) {

docRef.resizeImage(newImgSize, newImgSize, undefined, ResampleMethod.BICUBIC)

}

};


//#target photoshop

app.bringToFront(); // in case we double clicked the file

app.preferences.rulerUnits = Units.PIXELS;


if(documents.length==0) {

alert("Error: The native photoshop file (*.psd) must be opened.")

}


var docRef = app.activeDocument;

var savePath = "/c/photoshop/"; // this is where it will output your files

var counter = 0;


var savedState_psd = docRef.activeHistoryState; // used to start a new image


var txtFileRef = File("/c/a1/projects/pp/xxxxxxxxxxx/psd_vars.csv");


if (txtFileRef.exists)

{


txtFileRef.open('r') ;


while (!txtFileRef.eof) {

// Skip first line for header info

if (counter==0) {

var line=txtFileRef.readln();

counter++;

}


// Read line

var line=txtFileRef.readln();

var arrLine=new Array();


// Split line, use comma as delimiter

arrLine = line.split(",");


// Assign variables to field values

var domain_name1=arrLine[0];

var domain_name2=arrLine[1];


var changeableLayer1 = app.activeDocument.artLayers.getByName("001");

var changeableLayer1a = app.activeDocument.artLayers.getByName("001a");

var changeableLayer1b = app.activeDocument.artLayers.getByName("001b");

var changeableLayer1c = app.activeDocument.artLayers.getByName("001c");

var changeableLayer2 = app.activeDocument.artLayers.getByName("002");

var changeableLayer2a = app.activeDocument.artLayers.getByName("002a");

var changeableLayer2b = app.activeDocument.artLayers.getByName("002b");

var changeableLayer3 = app.activeDocument.artLayers.getByName("003");

var changeableLayer3a = app.activeDocument.artLayers.getByName("003a");

var changeableLayer3b = app.activeDocument.artLayers.getByName("003b");

var changeableLayer4 = app.activeDocument.artLayers.getByName("004");

var changeableLayer4a = app.activeDocument.artLayers.getByName("004a");

var changeableLayer4b = app.activeDocument.artLayers.getByName("004b");

var changeableLayer5 = app.activeDocument.artLayers.getByName("005");

var changeableLayer5a = app.activeDocument.artLayers.getByName("005a");

var changeableLayer5b = app.activeDocument.artLayers.getByName("005b");

.

.

.

.



// var changeableLayer3 = app.activeDocument.artLayers.getByName("filename");

changeableLayer1.textItem.contents = domain_name1;

changeableLayer1a.textItem.contents = domain_name1;

changeableLayer1b.textItem.contents = domain_name1;

changeableLayer1c.textItem.contents = domain_name1;

changeableLayer2.textItem.contents = domain_name1;

changeableLayer2a.textItem.contents = domain_name1;

changeableLayer2b.textItem.contents = domain_name1;

changeableLayer3.textItem.contents = domain_name1;

changeableLayer3a.textItem.contents = domain_name1;

changeableLayer3b.textItem.contents = domain_name1;

changeableLayer4.textItem.contents = domain_name1;

changeableLayer4a.textItem.contents = domain_name1;

changeableLayer4b.textItem.contents = domain_name1;

changeableLayer5.textItem.contents = domain_name1;

changeableLayer5a.textItem.contents = domain_name1;

changeableLayer5b.textItem.contents = domain_name1;

.

.

.

.


if (domain_name1.length <= 15) {

activeDocument.layers["003"].textItem.size = 34;

}

if (domain_name1.length <= 15) {

activeDocument.layers["003a"].textItem.size = 24;

}

if (domain_name1.length <= 15) {

activeDocument.layers["004"].textItem.size = 50;

}

if (domain_name1.length <= 15) {

activeDocument.layers["004a"].textItem.size = 25;

}

if (domain_name1.length <= 15) {

activeDocument.layers["004b"].textItem.size = 32;

}

if (domain_name1.length <= 15) {

activeDocument.layers["005"].textItem.size = 70;

}

if (domain_name1.length <= 15) {

activeDocument.layers["005a"].textItem.size = 40;

}

if (domain_name1.length <= 15) {

activeDocument.layers["005b"].textItem.size = 70;

}

.

.

.

.


// changeableLayer3.textItem.contents = file_name;

var photoName = domain_name1;


var savedState = docRef.activeHistoryState;



// ======================================================= export _l (600x520)

//fitImage(600);

ExportJpg("_l.jpg");


}//loop to next line

txtFileRef.close()


};


// =======================================================


// ensure that there is at least one document open; if not, display error message


// =======================================================

//docRef.activeHistoryState = savedState;

docRef = null;

alert("Process complete!");


TOPICS
Actions and scripting
1.1K
Translate
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
Adobe
Guru ,
Jun 17, 2009 Jun 17, 2009

I don't think it is a CS4 issue. It seems that exporting using save for web uses the last SFW setting in the GUI. Try doing a normal save for web and make sure that all slices are selected in the slice dropdown. It sounds like it is now set to selected slices ( which would be the last one created )

Translate
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
New Here ,
Jun 17, 2009 Jun 17, 2009

Wow...... THANK YOU very very much for this answer, it works now. Can't believe it was something this simple lol...

Is there anyway to force "save all slices" from the script? Thanks again.
Mitch

Translate
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
Guru ,
Jun 17, 2009 Jun 17, 2009
LATEST

As far as I know there is no way to change those setting using a script. You just have to keep that in mind when you run the script and let other users know to check those settings if you share your script.

Translate
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