Copy link to clipboard
Copied
Hi dear community, I need a bit of help from you.
I'm trying to develop a bridge script that from a root folder select images that shares some criteria (for now i'm doing this with names eg. aaa_base, jpeg, aaa_02.jpeg, aaa:03.jpeg) and then load the images in layers, run some commands in ps and saves to psd.
It's a while i'm tring to achieve this but i'm stucked...
At the present moment, i'm able to select the pictures that shares the neme criteria, and eventually stack them in bridge. problems comes when it's time to load them in ps. I tryed to achieve the result in different ways but no success at all...
The code is the result of different scripts i found on this and other communities, but i'm not a develepor at all, and in the end i feel i'm far away from the result... can someone help me out?
the file "Load.jsx" in the code is the "Load files into stack.jsx " of ps.
i was wondering if there's a way to call directly from bridge tools->photoshop->load files into layers but i'm not able to find that option...
I appreciate any help, thank you.
var fileList = Folder(app.document.presentationPath).getFiles("*base*");
for(var a in fileList) {
var firstFile = decodeURI(fileList[a].name.match(/[^_]*/));
var filesToStack = Folder(app.document.presentationPath).getFiles("*"+firstFile+"*");
if (filesToStack.length > 1 ) {
app.document.deselectAll();
for(var s in filesToStack) {
app.document.select(new Thumbnail(filesToStack[s]));
}
var bt = new BridgeTalk;
bt.target = "photoshop";
app.bringToFront();
var loadLayersFromScript = true;
//var strPresets = localize ("$$$/ApplicationPresetsFolder/Presets=Presets");
//var strScripts = localize ("$$$/PSBI/Automate/ImageProcessor/Photoshop/Scripts=Scripts");
var strFile2Stack = "Load.jsx";
var ipFilePath ="C:/"+ strFile2Stack;
$.writeln(ipFilePath);
var ipFile = new File (ipFilePath);
$.evalFile( ipFile );
loadLayers.intoStack(app.document.selections);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
var outputFolder = new Folder("/stack");
if(!outputFolder.exists) outputFolder.create();
var saveFile = new File(outputFolder + '/'+ Name +'.psd');
var Count = activeDocument.layers.length;
for(var d = 0 ;d < Count; d++) {
activeDocument.activeLayer = activeDocument.layers;
/* amend to use your action N.B. it is case sensitive */
doAction("Action Name","Action Set");
}
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Copy link to clipboard
Copied
Create an action that runs the desired Photoshop script then use the Batch command to send files to Photoshop and apply the action.
Copy link to clipboard
Copied
Thank you Lumigraphics, this is an hint of course!
But how can i call the PS batch command via script?
Copy link to clipboard
Copied
Adobe has sample scripts showing how to use BridgeTalk, in the various SDKs.
Copy link to clipboard
Copied
Your post has been edited. Next time for readability please use </> icon while posting your codes.
Avoiding multi spaces between lines and using indentation raise your chances to find the help 😉
Copy link to clipboard
Copied
Thank you a lot kukurykus! Next time i'll do better!
Copy link to clipboard
Copied
i share my working script for anyone in need
#target bridge
if( BridgeTalk.appName == "bridge" ) {
stacksToLayersII = new MenuElement("command", "combine to stacks and Stacks To LayersII", "at the end of submenu/Stack");
}
stacksToLayersII.onSelect = function () {
stakkatutto();
var stacks = app.document.stacks;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
var stackFiles = getStackFiles( stacks[s] );
var Name = decodeURI(stackFiles[0].name).replace(/\.[^\.]+$/, '');
if(stackFiles.length> 1){
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+stackFiles.toSource() + "," + Name.toSource() +");");
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
bt.send(500);
}
}
function getStackFiles( stack ){
var files = new Array();
for (var m = 0; m <= app.document.stacks.length; m++){
for( var f = 0; f<stack.thumbnails.length;f++){
files.push(stack.thumbnails[f].spec);
}
return files;
}
};
function myReturnValue(str){
res = str;
}
function psRemote(stackFiles,Name){
app.bringToFront();
var loadLayersFromScript = true;
var strPresets = localize ("$$$/ApplicationPresetsFolder/Presets=Presets");
var strScripts = localize ("$$$/PSBI/Automate/ImageProcessor/Photoshop/Scripts=Scripts");
var strFile2Stack = "Load Files into Stack.jsx";
var ipFilePath = app.path + "/" + strPresets + "/" + strScripts + "/" + strFile2Stack;
var ipFile = new File (ipFilePath);
$.evalFile( ipFile );
loadLayers.intoStack(stackFiles);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
var BT = new BridgeTalk();
BT.target='bridge';
BT.body ="var ftn = " + script.toSource() + "; ftn();";
BT.onResult = function( inBT ) { inFolder = inBT.body; }
BT.onError = function( ohShi ) { alert(ohShi.body)}
BT.send(10);
var outputFolder = new Folder(inFolder + "/Combined");
if(!outputFolder.exists) outputFolder.create();
var saveFile = new File(outputFolder + '/'+ Name +'.tif');
try{
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}catch(e){alert(e + "\n" + e.line);};
function script(){
return decodeURI(Folder(app.document.presentationPath).fullName).toString();
}
}
function stakkatutto() {
var fileList = Folder(app.document.presentationPath).getFiles("*base*");
for(var a in fileList){
var firstFile = decodeURI(fileList[a].name.match(/[^_]*/));
var filesToStack = Folder(app.document.presentationPath).getFiles("*"+firstFile+"*");
if(filesToStack.length > 1 ) {
app.document.deselectAll();
for(var s in filesToStack){
app.document.select(new Thumbnail(filesToStack[s]));
}
app.document.chooseMenuItem("StackGroup");
}
}
}
};
this is the result of several scripts found on this community forum, so i thanks all the people who support the others!