Is it possible? Rename Layers to Blending Mode

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

coreyarte
Posts: 7
Joined: Sat Sep 29, 2018 10:22 pm

Is it possible? Rename Layers to Blending Mode

Post by coreyarte »

Hello everyone,
I have a script I want to create and wonder if its even possible to make.
I want to click a botton or menu item, that will rename all layers that are unnamed (like generic Layer003, Layer 004, ect) and rename them according to their blending mode. So for example if a layer is named Layer004 and is an overlay layer, when you run the script it will be renamed to Overlay004.

Is this possible to make? I've never scripted before. Would really help with organizing layers.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Kukurykus »

Make a loop over layers in document, then checking name of each check its blending mode if the layer name is generic to rename it to.
coreyarte
Posts: 7
Joined: Sat Sep 29, 2018 10:22 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by coreyarte »

Kukurykus wrote: Thu Dec 24, 2020 12:05 pm Make a loop over layers in document, then checking name of each check its blending mode if the layer name is generic to rename it to.
Thats great that its possible! You sound like its not too difficult to do as well.
Do you or anyone here think you'd be willing to do it for payment? I'd be willing to pay for such a useful script.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Kukurykus »

Sure, leave your E-mail in a private message to me.

So generic layers are only those starting with 'Layer' word plus they're suffixed with 3 digit numbers?
coreyarte
Posts: 7
Joined: Sat Sep 29, 2018 10:22 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by coreyarte »

Hello Kukurykus sorry I didnt realize you replied!
Yes, generic would just be any layer with default name. Like LAYER and a number like you stated.
You think this might be simple or complicated to do?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Kukurykus »

For me with years of experience not, just free time lately makes it harder ;)
coreyarte
Posts: 7
Joined: Sat Sep 29, 2018 10:22 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by coreyarte »

No problem! DO you know of a good resource to learn for myself to start?
Or a place where I can pay someone to make it for me?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Kukurykus »

I have no time to do it for free, so if you were interested I asked you to leave your E-Mail in PM but you haven't yet ;)
User avatar
Stephen_A_Marsh
Posts: 29
Joined: Sun Aug 04, 2019 12:37 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Stephen_A_Marsh »

An old topic, lots of good stuff for a intermediate-beginner to practice and learn!

The following code is only for the active layer, I'll post code to process all layers once I am happy.

EDIT: Of course, the question of what happens if a layer blend mode changes after the layer has been renamed is hanging out there...

Code: Select all

/* https://www.ps-scripts.com/viewtopic.php?p=170072#p170072 */

// Active Layer to Blend Mode Name.jsx
// Stephen Marsh, v1.0 6th December 2021

#target photoshop

// If layer name = Layer 1 | Layer 02 | Layer 003 etc. (case sensitive)
if (app.activeDocument.activeLayer.name.match(/^Layer \d+/)) {
    // Call function
    lyrNameToBlendName();
}

function lyrNameToBlendName() {
    var lyrBlendMode = app.activeDocument.activeLayer.blendMode.toString().replace(/(?:^.+\.)(.+)/, '$1');
    // UpperCase default
    var lyrBlendName = lyrBlendMode.replace(/LIGHT$/, ' LIGHT').replace(/MIX$/, ' MIX').replace(/COLOR$/, ' COLOR').replace(/DODGE$/, ' DODGE').replace(/BURN$/, ' BURN').replace(/LINEAR DODGE$/, 'LINEAR DODGE (ADD)');
    var suffix = app.activeDocument.activeLayer.name.replace(/(?:.+)( \d+$)/, '$1');
    // LowerCase optional
    // var lyrBlendNameLC = lyrBlendName.toLowerCase();
    // app.activeDocument.activeLayer.name = lyrBlendNameLC + suffix;
    app.activeDocument.activeLayer.name = lyrBlendName + suffix;
}
Last edited by Stephen_A_Marsh on Sat Dec 11, 2021 11:55 am, edited 2 times in total.
User avatar
Stephen_A_Marsh
Posts: 29
Joined: Sun Aug 04, 2019 12:37 pm

Re: Is it possible? Rename Layers to Blending Mode

Post by Stephen_A_Marsh »

NOTE: I had to pull the original code for Proper Case text as it was failing (it didn't fail before posting!)...

EDIT - 11th December 2021: Here is the updated code for Proper Case conversion!

Code: Select all

/* https://www.ps-scripts.com/viewtopic.php?p=170072#p170072 */

// Active Layer to Blend Mode Name.jsx
// Stephen Marsh, v1.1 11th December 2021

#target photoshop

// If layer name = Layer 1 | Layer 02 | Layer 003 etc. (case sensitive)
if (app.activeDocument.activeLayer.name.match(/^Layer \d+/)) {
    // Call function
    lyrNameToBlendName();
}

function lyrNameToBlendName() {
    var lyrBlendMode = app.activeDocument.activeLayer.blendMode.toString().replace(/(?:^.+\.)(.+)/, '$1');
    var lyrBlendLC = lyrBlendMode.replace(/LIGHT$/, ' LIGHT').replace(/MIX$/, ' MIX').replace(/COLOR$/, ' COLOR').replace(/DODGE$/, ' DODGE').replace(/BURN$/, ' BURN').replace(/LINEAR DODGE$/, 'LINEAR DODGE (ADD)').toLowerCase();
    var lyrBlendPC = (sentenceCase(lyrBlendLC));

    function sentenceCase(str) {
        /* https://www.geeksforgeeks.org/convert-string-to-title-case-in-javascript/ */
        if ((str === null) || (str === ''))
            return false;
        else
            str = str.toString();
        return str.replace(/\w\S*/g,
            function (txt) {
                return txt.charAt(0).toUpperCase() +
                    txt.substr(1).toLowerCase();
            });
    }

    var suffix = app.activeDocument.activeLayer.name.replace(/(?:.+)( \d+$)/, '$1');
    app.activeDocument.activeLayer.name = lyrBlendPC + suffix;
}