create layered image stack from files and align
Hi everyone,
i'm pretty new to scripting so i would really love to have some suggestions. i'm trying to code a script that does the following steps:
1.open the selected files (not from folder) in a layered photoshop stack
2. align them
3. read the shortest layer name and saves to a variable (let's call it "product")
4. create some layerset
5. saves the file to the parent directory of the source with the "product" name
6. close the file
i searched on the forum for a solution for long time but my scripting skills are too basic.
i'm not sure if it's better to do this form bridge or directly from ps.
at the moment i'm trying both the ways but don't figure out how to solve.
for the bridge script i've found some hint from this forum but this doesn't open the layered stack...
#target bridge
/*if( BridgeTalk.appName == "bridge" ) {
stacksToLayers = new MenuElement("command", "Stacks To Layers", "at the end of Tools");
}
stacksToLayers.onSelect = function () { */
var stacks = app.document.selections;
var stackCount = stacks.length;
for(var s = 0;s<stackCount;s++){
var stackFiles = getStackFiles( stacks
);if(stackFiles.length> 1){
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+stackFiles.toSource()+");");
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
bt.send(500);
}
}
function getStackFiles( stack ){
var files = new Array();
for( var f = 0; f<stackCount;f++){
files.push(stacks
.spec); }
return files;
};
function myReturnValue(str){
res = str;
}
// don't have comments in the psRemote function
function psRemote(stackFiles){
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);
var saveFile = new File('~/desktop/'+app.activeDocument.name+'.psd');
app.activeDocument.saveAs(saveFile);
}
//}// app.activeDocument.close(SaveOptions.DONOTSA
VECHANGES);
from debugging it stops on bt.send(500); line repeating this command....
$.level = 0; app.synchronousMode = false;
on the ps script part i have similar issue, the layered files doesn't open... here the code
var fileList= File.openDialog("seleziona i files",undefined,true);
for (i = 0; i <= fileList.length-1; i++) {
alert(fileList.path + "/" +fileList.name);
// or open or do somethig else
}
if ( fileList != null ){
runLoadStack();
}
function runLoadStack( fileList ){
var loadLayersFromScript = true;// must be set before the include
// @include '/C/Program Files/Adobe/Adobe Photoshop CC 2017/Presets/Scripts/Load Files into Stack.jsx'
var aFlag = true;
loadLayers.intoStack( fileList, aFlag );
}
the other parts of the script i should be able to manage...
anyone could help me?
thank you a lot and a great hug form Italy
Alessio
