• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Want to Automate saving an Image with multiple layer with each named with File name+Layer name

Community Beginner ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied


While I have good knowlede of Photoshop in the editing side, I am inept when it comes to coding and scripting. So any help would be very appreciated. Thank you

I have a project where I have hundreds of images that I need to apply a dozen layers to. For cataloging puporses it seems that it would be best to name them by image name and add the layer name. I will end up with a dozen version of each image.

How do I create an action that will save the image with the File Name and add the layer's name. Then hide the current layer and show the next layer. Save as before and so on. For example I would end up with: 
1st image-  Swiss01_D01, Swiss01_D02, Swiss01_D03, Swiss01_D04
2nd image- Swiss02_D01, Swiss02_D02, Swiss02_D03, Swiss02_D04
3nd image- Swiss03_D01, Swiss03_D02, Swiss03_D03, Swiss03_D04...

Photoshop CC 2022
Mac OS Ventura

TOPICS
Actions and scripting

Views

415

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 15, 2023 Jan 15, 2023

 

edited

// save combinations of lowermost layer with one layer each;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var docName = myDocument.name;
    try {
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    var docPath = myDocument.path;
    }
    catch (e) {
    var docPath = "~/Desktop"
    };    
    var theLayers = collectLayersNamesIndexAndIdentifier();
// jpg options;
    var jpegOptions = new JPEGSaveOptions();
    j
...

Likes

Translate

Translate
Community Expert ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied

What file format? 

An Action will not suffice and you need a Script. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

I wanted to comeback and thank you. Wow, that script worked so well. AMAZING. Thanks again.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

LATEST

Did you make any headway regarding the metadata? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied

 

edited

// save combinations of lowermost layer with one layer each;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var docName = myDocument.name;
    try {
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    var docPath = myDocument.path;
    }
    catch (e) {
    var docPath = "~/Desktop"
    };    
    var theLayers = collectLayersNamesIndexAndIdentifier();
// jpg options;
    var jpegOptions = new JPEGSaveOptions();
    jpegOptions.quality = 9;
    jpegOptions.embedColorProfile = true;
    jpegOptions.matte = MatteType.NONE;
// hide except lowermost layer;
    showOrHideLayerById (theLayers[0][2], false);
    hideOtherLayersById (theLayers[0][2]);
// save copies;
    for (var m = 1; m < theLayers.length; m++) {
        showOrHideLayerById (theLayers[m][2], false);
        myDocument.saveAs((new File(docPath+"/"+ theLayers[0][0] + "_" + theLayers[m][0] + ".jpg")), jpegOptions, true);  
        showOrHideLayerById (theLayers[m][2], true);
    };
    };
////// collect layers //////
function collectLayersNamesIndexAndIdentifier () {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" /*&& isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theVisibility = layerDesc.getBoolean(stringIDToTypeID('visible'));
theLayers.push([theName, theIndex, theID, theVisibility])
};
}
catch (e) {};
};
return theLayers
};
// 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); 
    }
    };
////// hide all other layers //////
function hideOtherLayersById (theID) {
    // =======================================================
        var desc4 = new ActionDescriptor();
            var list1 = new ActionList();
                var ref3 = new ActionReference();
                ref3.putIdentifier(charIDToTypeID("Lyr "), theID);
//                ref3.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
            list1.putReference( ref3 );
        desc4.putList( charIDToTypeID( "null" ), list1 );
        desc4.putBoolean( charIDToTypeID( "TglO" ), true );
    executeAction( charIDToTypeID( "Shw " ), desc4, DialogModes.NO );
    };
////// show or hide layer //////
function showOrHideLayerById (theID, theVisibility) {
    if (theVisibility == true) {var idhide = stringIDToTypeID( "hide" )}
    else {var idhide = stringIDToTypeID( "show" )};
    var desc22 = new ActionDescriptor();
    var list2 = new ActionList();
    var ref8 = new ActionReference();
    ref8.putIdentifier( stringIDToTypeID( "layer" ), theID );
    list2.putReference( ref8 );
    desc22.putList( stringIDToTypeID( "null" ), list2 );
    executeAction( idhide, desc22, DialogModes.NO );
};

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied

Wow, thanks. Did you write that on the fly? This is definitely above my pay grade. I will look for an article about how to install.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied

Save the code as a txt-file, change the extension to .jsx and copy it into Photoshop’s Presets/Scripts-Folder; after restarting Photoshop it should be available under File > Scripts and can be assigned a Shortcut or used in an Action. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

quote

I will look for an article about how to install.

 


By apatron@aol.com

 

Here you go:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines