Copy link to clipboard
Copied
Hi,
Can any one help to stack multiple number of images into layers from a particular folder with the layer name.
Example:
I have 3 layer and each layer is named as a1, a2, and a3. I need a script of take a1 file from a folder(from desktop) and place it into a1 layer and the same need to repeat for the rest.
So I will get a1 image into a1 layer, a2 image into a2 layer,...
Thanks in advance
Does this help?
...
// replace layers of a certain name with
// 2014, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
// get folder;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i)};
var theseFiles = new Array;
for (var n = 0; n < theFiles.length; n++) {
theseFiles.push ([theFiles
.name.match(/(.*)\.[^\.]+$/)[1], theFiles ]) };
// of there are files proceed;
if (theseFiles.length
Copy link to clipboard
Copied
How is
File > Scripts > Load Files into Stack
falling short?
Copy link to clipboard
Copied
Hi Pfaffen,
Thanks for the reply, using the option mentioned by you we can stack the iimage, however the folded in my desktop having multiple num of files, from them we need to pick the particular files and place into particular layer.
Example:
The Desktop folder has 50 images, of this I need to stack only 3 images into layers.
The layers are already named with the file name mentioned in the desktop folder, the respective named file need to plaace into respective named layer.
Hope you get what I am trying to tell.
Copy link to clipboard
Copied
Sorry, I had not understood that you want to replace the Layers with the images of the corresponding names.
Copy link to clipboard
Copied
Hi,
No, no need to replace the layer, just need to place the image into layer. If a layer is named as "Shine", it need to search for the file named as "Shine" on desktop folder and place the image into the layer "Shine".
Copy link to clipboard
Copied
How good is your Scripting?
Could you please post a screenshot of the image with the Layers Panel visible?
Copy link to clipboard
Copied
Hi Pfaffen,
I am really beginner in scripting.
I have attached a sample screen grab for better understanding.
The layers are already named with the file names, we need to search with the layer name and place the images into respective layers.
Copy link to clipboard
Copied
You can also use Adobe Bridge to select the images files then use menu Tools>Photoshop>Load files into a stack.
Also you can use a Script like my PastImageRoll to load resize images layout in a document.
http://www.mouseprints.net/old/dpr/PasteImageRoll.jsx
Copy link to clipboard
Copied
Thank you Mack for your time,
The option is good, but I have 2421 files in a folder, out of this only 21 images are required and its really difficult to find visually.
A psd file with multiple layers with the file name is already made, so just we need to read the layer name and place the respective image from desktop folder into respective layer.
Copy link to clipboard
Copied
Shine_RRD wrote:
The option is good, but I have 2421 files in a folder, out of this only 21 images are required and its really difficult to find visually.
I do not understand why there would be if you using Windows both the Bridge and Windows File open Dialog show Thumbnails for images within a folder if there is one file or 2421 file. Using Ctrl+Click on file thumbnails and using the scroll bars you should be able to select the 21 Image files you need. You would need to install Codecs if you need Thumbnails for RAW and PSD files in window dialogs. I would think Bridge would not be a problem on MAC or PC and does its own thumbnails. Mac users may need some add-on for thumbnails in mac dialogs. I don't use a mac so I don't know it the is required or not.
The first image I posted was two screen captures first one showing the displaying thumbnails of images in a folder with five selected 21 could be selected all could be selected. In the same capture menu tools>Photoshop>Load Files into stack is shown.
The second showed how the display looked after tools>Photoshop>Load Files ran a PSD with five image layer with layer name of the image file name. Its an open document the cam be saved as a PSD file.
A PSd image file can be placed in as a flat image layer or as a smart object layer that has an embedded or linked smart object that is a layered PSD file.
How PasteImageRoll works Paste Image Roll script and Picture Package support documentation
Copy link to clipboard
Copied
Do you know you can change windows file dialog details file list to thumbnails list that have different thumbnail sizes and that you can use Ctrl+Click on Image Icons one at a time to select the 21 image files you want... Here the 21 thumbnails with borders have been selected using Ctrl+Clicks....
Copy link to clipboard
Copied
Hi Mack,
The above files and file names are show only for example.
We receive 2 folders, 1 with source image (raw image) and another 1 with reference image (reference for color). The name of the file (Source file) and the respective reference files will be marked in an excel by our art director, so only possibility is opening the images by reading the file names. The file names are bit complicated to pick the exact reference files from a folder with large num of files (snapshot shown below for reference).
I have already made a script to read the excel date and load the reference file names (only file names from excel) into photoshop layers, however what I need now is, to read the layer name and place the file into the correct layer.
Copy link to clipboard
Copied
Shine_RRD wrote:
I have already made a script to read the excel date and load the reference file names (only file names from excel) into photoshop layers, however what I need now is, to read the layer name and place the file into the correct layer.
I do not understand what you trying to do. If you wrote a script that reads a excel file to get a list of file names into an array when you place these files into a document as smart smart object layers each layer's layer name will be set to the filename by Photoshop's place operation. If on the other side if you use a procedure that open file select all, Copy, close nosave and paste in a layer Photoshop will name the new layer the next layer "n" name you would then need to set the current layer to the filename of the document copied to the clipboard. Like I do in my PasteImageRoll script
for (var i=0;i<file.length;i++) {
if (file instanceof File && !file.name.match(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|psd|tif|tiff|jpg|jpe|jpeg|png|bmp|)$/i) ) continue; //next file if not matched
app.load(file); // load it into a document <------------------------------------------------------------------------------OPEN A DOCUMENT
var backFile= app.activeDocument; // image document
var imageName = backFile.name; // image file name <---------------------------------------------------------------REMEMBER FILE NAME TO NAME IMAGE LAYER
flatten(); //handle layered images // flatten active document incase its layered.
if (rotateForBestFit) {
if (backFile.width.value<backFile.height.value&&width>height ) { backFile.rotateCanvas(-90.0); } // Rotate portraits
if (backFile.height.value<backFile.width.value&&height>width ) { backFile.rotateCanvas(-90.0); } // Rotate landscapes
}
if (backFile.width.value/backFile.height.value > width/height) { backFile.resizeImage(null, height, res, ResampleMethod.BICUBIC); } // wider
else {backFile.resizeImage(width, null, res, ResampleMethod.BICUBIC);} // same aspect ratio or taller
backFile.selection.selectAll(); <----------------------------------------------------------------------------------------------SELECT ALL
backFile.selection.copy(); //copy resized image into clipboard <----------------------------------------------------COPY TO CLIPBOARD
backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes <---------CLOSE DOCUMENT NOSAVE
for (var n=0;n<copies;n++) { // number of copies
var x =pasted*(width+whitespace)+borderspace;
var y =currrow*(height+whitespace)+borderspace;
var selectedRegion = Array(Array(x,y), Array(x+width,y), Array(x+width,y+height), Array(x,y+height));
doc.selection.select(selectedRegion);
doc.paste(true); //paste image into masked layer your document <------------------------------------ PASTE IN CLIPBOARD AS A LAYER "TRUE" MAKES IT INTO A MASKED LAYER
doc.activeLayer.name=imageName; //label layer with image file name <---------------------- CHANGE THE LAYER NAME FOR PHPTOSHOP DEFALT NAME TO IMAGE FILE NAME
doc.selection.select(selectedRegion);
align('AdCH'); align('AdCV');
doc.selection.deselect();
pasted++
if ( pasted==cols ) { pasted=0; currrow++; }
}
}
Copy link to clipboard
Copied
Does this help?
// replace layers of a certain name with
// 2014, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
// get folder;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd)$/i)};
var theseFiles = new Array;
for (var n = 0; n < theFiles.length; n++) {
theseFiles.push ([theFiles
.name.match(/(.*)\.[^\.]+$/)[1], theFiles ]) };
// of there are files proceed;
if (theseFiles.length > 0) {app.activeDocument.suspendHistory("replace", "main ()")};
};
////////////////////////////////////
function main () {
// the file;
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
theLayers.push([theName, theID])
/*if (theName == searchName) {
var boundsDesc = layerDesc.getObjectValue(stringIDToTypeID('bounds'));
var theTop = boundsDesc.getUnitDoubleValue(stringIDToTypeID('top'));
var theLeft = boundsDesc.getUnitDoubleValue(stringIDToTypeID('left'));
var theWidth = boundsDesc.getUnitDoubleValue(stringIDToTypeID('width'));
var theHeight = boundsDesc.getUnitDoubleValue(stringIDToTypeID('height'));
var theCenter = [theLeft+theWidth/2, theTop+theHeight/2];
selectLayerByIndex(m,false);
theArray.push([myDocument.activeLayer, theCenter, theWidth, theHeight])
};*/
};
}
catch (e) {};
};
////////////////////////////////////
for (var o = 0; o < theLayers.length; o++) {
var thisLayer = theLayers
; for (var p = 0; p < theseFiles.length; p++) {
if (theseFiles
[0] == thisLayer[0]) {
selectLayerByID(thisLayer[1],false);
var removeLayer = myDocument.activeLayer;
var theBounds = removeLayer.bounds;
var theSO = placeScaleRotateFile (theseFiles
[1], 0, 0, 100, 100, 0);
if (Number(theBounds[0]) == 0 && Number(theBounds[2]) == 0) {}
else {removeLayer.remove()};
}
}
};
// restore;
app.preferences.rulerUnits = originalUnits;
};
// by mike hale, via paul riggott;
// http://forums.adobe.com/message/1944754#1944754
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
////// place //////
function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle) {
// =======================================================
var idPlc = charIDToTypeID( "Plc " );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc5.putPath( idnull, new File( file ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc6 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idHrzn, idPxl, xOffset );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idVrtc, idPxl, yOffset );
var idOfst = charIDToTypeID( "Ofst" );
desc5.putObject( idOfst, idOfst, desc6 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idWdth, idPrc, theYScale );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idHght, idPrc, theXScale );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc5.putUnitDouble( idAngl, idAng,theAngle );
var idLnkd = charIDToTypeID( "Lnkd" );
desc5.putBoolean( idLnkd, true );
executeAction( idPlc, desc5, DialogModes.NO );
return app.activeDocument.activeLayer;
};
Copy link to clipboard
Copied
Hi Pfaffen,
Thanks a lot for the script, Its working as expected.
thnaks Mack for you time on this
Copy link to clipboard
Copied
Hi Pf,
The above script is working as expected, but if a layer name contains ".tif' along with the file name, then it not placing the files into layers.
EX: If a layer named "Shine.tif" then the respective file is not placing inside the layer, however if we rename the layer as "Shine" it will place the image.
It will be helpful if you can fix this for me
Copy link to clipboard
Copied
If your Scripting needs exceed the default Scripts you should familiarise yourself with basic Scripting concepts to be able to attempt solving your own problems.
Hints:
In the line
theseFiles.push ([theFiles
.name.match(/(.*)\.[^\.]+$/)[1], theFiles ])
the first element in the array is the file’s name without the suffix (the dot and the following letters).
The line
if (theseFiles
[0] == thisLayer[0]) {
compares the layer’s name and a file’s name without the suffix.
But an if clause can operate on more than one thing, for example an AND
if (a == b && c == d) {…
an OR
if (a == b || a == c) {…
Copy link to clipboard
Copied
Will try and let you know, thanks for the hint!