Batch psd/tiff Document creation with guides

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

Paul MR

Batch psd/tiff Document creation with guides

Post by Paul MR »

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

Batch psd/tiff Document creation with guides

Post by sachinrewa »

Hi Paul,

I think, I am only one step behind to achieve the result. Have you find the sample file to see? It you did not able to get the file, please guide me how can I send the sample file.
the code is giving error in:
Error 21: undefined is not an object.
Line 25

Regards,
Sachin
Paul MR

Batch psd/tiff Document creation with guides

Post by Paul MR »

That error might be that you have an error in your csv file.
I have put a check in for that now.
Yes I got the jpg but it does not help as it does not tell me where you want the guides and there is no information to match the csv details.
I will be away for a week now and not sure if I can get access to the internet but will try.

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;
if(line.length != 5){
    alert("You have an error in your csv file!\r" +line.toString());
    return;
    }
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);
}
sachinrewa

Batch psd/tiff Document creation with guides

Post by sachinrewa »

Hi Paul,

Thank you very much for your efforts to doing it very quickly and giving me your precious time.

Yes the error in csv file.
We reached at 99% of result. Right now the guides are in spine +.125 inch, it is ok. I need one more guide at spine +.25 inch both side of spine.
Second document in CMYK, save in .tif, and units in inch, if possible. I have changed preferences > units in inch, but find that 1 pxl differences in each guides position.

Regards,
sachin
sachinrewa

Batch psd/tiff Document creation with guides

Post by sachinrewa »

Hi Paul,

Are you back. Please have a look on it. if you want to see I have attached the link below.

http://dl.dropbox.com/u/31210650/sample.jpg

Regards,
Sachin