Batch psd/tiff Document creation with guides
Posted: Sun Jul 08, 2012 5:00 pm
I am not sure where you want the left and right guides.
Is this any better?
Code: Select all#target photoshop
main();
function main(){
var csvFile = File.openDialog("Open Comma-delimited File","comma-delimited(*.csv):*.csv;");
if(csvFile == null) return;
var outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder == null) return;
csvFile.open('r') ;
var csvString = csvFile.read();
csvFile.close();
csvString = csvString.split('\n');
// Change to suit
var Resolution = 300;
///////////////////////////////////////////
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
for(var a in csvString){
if(csvString[a].length <5 ) continue;
var line = csvString[a].split(',');
if(isNaN(Number(line[0].replace(/^\s+|\s+$/g,'')))) continue;
var docName = line[0].replace(/^\s+|\s+$/g,'');
var Height = Number(line[1].replace(/^\s+|\s+$/g,''));
var Width = Number(line[4].replace(/^\s+|\s+$/g,''));
var Spline = Number(line[3].replace(/^\s+|\s+$/g,''));
var docHeight = Resolution * (Height + 0.25);
var docWidth = Resolution * Width;
var docSpline = Resolution * Spline;
var Bleed = (Resolution * 0.25)/2;
var doc = app.documents.add(docWidth,docHeight,Resolution,docName,NewDocumentMode.RGB, DocumentFill.WHITE);
//Guides
var leftBleed = Bleed;
var rightBleed = docWidth - Bleed;
var topBleed = Bleed;
var bottomBleed = docHeight - Bleed;
var leftSpline = (docWidth/2) - (docSpline/2);
var rightSpline = (docWidth/2) + (docSpline/2);
var leftBleedSpline = leftSpline - Bleed;
var rightBleedSpline = rightSpline + Bleed;
guideLine(leftBleed,"Vrtc",'#Pxl');
guideLine(rightBleed,"Vrtc",'#Pxl');
guideLine(topBleed,"Hrzn",'#Pxl');
guideLine(bottomBleed,"Hrzn",'#Pxl');
guideLine(leftSpline,"Vrtc",'#Pxl');
guideLine(rightSpline,"Vrtc",'#Pxl');
guideLine(leftBleedSpline,"Vrtc",'#Pxl');
guideLine(rightBleedSpline,"Vrtc",'#Pxl');
var saveFile = File(outputFolder + "/" + docName + ".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
};
function guideLine(position, type,unit) {
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
Is this any better?
Code: Select all#target photoshop
main();
function main(){
var csvFile = File.openDialog("Open Comma-delimited File","comma-delimited(*.csv):*.csv;");
if(csvFile == null) return;
var outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder == null) return;
csvFile.open('r') ;
var csvString = csvFile.read();
csvFile.close();
csvString = csvString.split('\n');
// Change to suit
var Resolution = 300;
///////////////////////////////////////////
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
for(var a in csvString){
if(csvString[a].length <5 ) continue;
var line = csvString[a].split(',');
if(isNaN(Number(line[0].replace(/^\s+|\s+$/g,'')))) continue;
var docName = line[0].replace(/^\s+|\s+$/g,'');
var Height = Number(line[1].replace(/^\s+|\s+$/g,''));
var Width = Number(line[4].replace(/^\s+|\s+$/g,''));
var Spline = Number(line[3].replace(/^\s+|\s+$/g,''));
var docHeight = Resolution * (Height + 0.25);
var docWidth = Resolution * Width;
var docSpline = Resolution * Spline;
var Bleed = (Resolution * 0.25)/2;
var doc = app.documents.add(docWidth,docHeight,Resolution,docName,NewDocumentMode.RGB, DocumentFill.WHITE);
//Guides
var leftBleed = Bleed;
var rightBleed = docWidth - Bleed;
var topBleed = Bleed;
var bottomBleed = docHeight - Bleed;
var leftSpline = (docWidth/2) - (docSpline/2);
var rightSpline = (docWidth/2) + (docSpline/2);
var leftBleedSpline = leftSpline - Bleed;
var rightBleedSpline = rightSpline + Bleed;
guideLine(leftBleed,"Vrtc",'#Pxl');
guideLine(rightBleed,"Vrtc",'#Pxl');
guideLine(topBleed,"Hrzn",'#Pxl');
guideLine(bottomBleed,"Hrzn",'#Pxl');
guideLine(leftSpline,"Vrtc",'#Pxl');
guideLine(rightSpline,"Vrtc",'#Pxl');
guideLine(leftBleedSpline,"Vrtc",'#Pxl');
guideLine(rightBleedSpline,"Vrtc",'#Pxl');
var saveFile = File(outputFolder + "/" + docName + ".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
};
function guideLine(position, type,unit) {
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}