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

Photoshop Script - Copy layer attributes (blend, opacity & fill) and apply to the group it is in.

Explorer ,
Jan 27, 2022 Jan 27, 2022

Hi all! I'm creating some Actions and scripts to help me with my work, but I've reached this point where I can't find a solution. I appreciate any help.
I need to get the properties of a layer (Blend mode, opacity and fill), inside a group, and apply these properties to the group that this layer is in, and put the layer back in Normal Blend Mode, 100% fill and 100 % opacity. Would this be possible through a script?

 

Thanks!

TOPICS
Actions and scripting
1.8K
Translate
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 2 Correct answers

Community Expert , Jan 28, 2022 Jan 28, 2022

Nice one Chuck, for some reason I thought that this would take AM code to do all that!

 

It appears that the parent layer set is not changing fill opacity for me. Blend mode and layer opacity change, but fill opacity is stubborn.

 

The original layer is being reset correctly.

 

EDIT: The only way that I could get the layer set to change fill opacity was to use SL code. The crazy thing is that the fill opacity works fine with the artLayer, just not with the LayerSet?

 

/* 
https://community.adobe
...
Translate
Community Expert , Jan 28, 2022 Jan 28, 2022

For some reason, my first code worked, now, today, it doesn't, so here it is with AM code for the fill opacity:

#target photoshop
var doc = activeDocument;
var curLay = doc.activeLayer
var layPar = curLay.parent
doc.activeLayer = layPar;
var isArt = isArtBoard ();
doc.activeLayer = curLay;

if(layPar.typename=='LayerSet' && isArt == false){
    doc.activeLayer= layPar
    layPar.opacity = curLay.opacity;
    fillOp (curLay.fillOpacity)
    //ayPar.fillOpacity = curLay.fillOpacity;
    layPar.ble
...
Translate
Adobe
Community Expert ,
Jan 27, 2022 Jan 27, 2022

That should be pretty easy, but I'm not at my computer to write out the test code. I'll  try later, if someone else doesn't answer first. 

Translate
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, 2022 Jan 27, 2022

Try this:

 

#target photoshop
var doc = activeDocument;
var curLay = doc.activeLayer
var layPar = curLay.parent
doc.activeLayer = layPar;
var isArt = isArtBoard ();
doc.activeLayer = curLay;

if(layPar.typename=='LayerSet' && isArt == false){
    
    layPar.opacity = curLay.opacity;
    layPar.fillOpacity = curLay.fillOpacity;
    layPar.blendMode = curLay.blendMode;
    curLay.opacity = 100;
    curLay.fillOpacity = 100;
    curLay.blendMode = BlendMode.NORMAL 
    }

function isArtBoard(){
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
    }; 

 

Translate
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 28, 2022 Jan 28, 2022

Nice one Chuck, for some reason I thought that this would take AM code to do all that!

 

It appears that the parent layer set is not changing fill opacity for me. Blend mode and layer opacity change, but fill opacity is stubborn.

 

The original layer is being reset correctly.

 

EDIT: The only way that I could get the layer set to change fill opacity was to use SL code. The crazy thing is that the fill opacity works fine with the artLayer, just not with the LayerSet?

 

/* 
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-script-copy-layer-attributes-blend-opacity-amp-fill-and-apply-to-the-group-it-is-in/td-p/12712083 
*/

#target photoshop

// Set the global variables
var isArt = isArtBoard();
var lyr = app.activeDocument.activeLayer;
var lyrSet = lyr.parent;
var lyrOp = lyr.opacity;
var lyrFillOp = lyr.fillOpacity;
var lyrBld = lyr.blendMode;

if (lyrSet.typename === 'LayerSet' && isArt === false) {

    // Set the blend mode
    lyrSet.blendMode = lyrBld;
    
    // Set the opacity
    lyrSet.opacity = Math.round(lyrOp);
    
    // Select the layer set/group
    app.activeDocument.activeLayer = lyrSet;

    // Set the fill opacity for the layer set/group
    setFillOp(lyrFillOp);
    
    // Select the layer
    app.activeDocument.activeLayer = lyr;
    
    // Set the blend mode
    lyr.blendMode = BlendMode.NORMAL;
    
    // Set the opacity
    lyr.opacity = 100;
    
    // Set the fill opacity
    lyr.fillOpacity = 100;

}


// Functions

function setFillOp(fillOpacity) {
    // There is no OM property for LayerSet.fillOpacity
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
	descriptor.putReference(s2t("null"), reference);
	descriptor2.putUnitDouble(s2t("fillOpacity"), s2t("percentUnit"), fillOpacity);
	descriptor.putObject(s2t("to"), s2t("layer"), descriptor2);
	executeAction(s2t("set"), descriptor, DialogModes.NO);
}

function isArtBoard() {
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
}

 

Translate
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 28, 2022 Jan 28, 2022

EDIT: The only way that I could get the layer set to change fill opacity was to use SL code. The crazy thing is that the fill opacity works fine with the artLayer, just not with the LayerSet?

 

Ah, I just answered my own question... I can't find a property in the JS reference for LayerSet.fillOpacity – which explains why this can't be treated as a standard layer and why the scripting listener recorded AM code works. So not so crazy in hindsight!

Translate
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
LEGEND ,
Jan 28, 2022 Jan 28, 2022

Why to comment commands which explicitly say themselves their function? 😕

Translate
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 28, 2022 Jan 28, 2022

As searchable keywords when I am trawling through my script collection folder looking to reuse code.

Translate
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
LEGEND ,
Jan 28, 2022 Jan 28, 2022

If your folder is outside then these codes over here can be free of personal comments.

Translate
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 28, 2022 Jan 28, 2022

I'll give your suggestion all of the consideration that it deserves.

Translate
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
LEGEND ,
Jan 28, 2022 Jan 28, 2022

And how much of consideration that suggestion deserves? 😛

Translate
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 28, 2022 Jan 28, 2022

😛

Translate
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 28, 2022 Jan 28, 2022

Meet me half way... I'll remove comments from my code if you add comments into your code postings! 😉

Translate
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
LEGEND ,
Jan 28, 2022 Jan 28, 2022

What if I'll be adding 10000 of same or any recognizable by me characters to each of my post with same explanation as you to find my posts easier, won't be it spamming?

Translate
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 28, 2022 Jan 28, 2022

Umm, I thought the fill opacity was working on the layerset I guess I'll have to double check. 

Translate
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 28, 2022 Jan 28, 2022

For some reason, my first code worked, now, today, it doesn't, so here it is with AM code for the fill opacity:

#target photoshop
var doc = activeDocument;
var curLay = doc.activeLayer
var layPar = curLay.parent
doc.activeLayer = layPar;
var isArt = isArtBoard ();
doc.activeLayer = curLay;

if(layPar.typename=='LayerSet' && isArt == false){
    doc.activeLayer= layPar
    layPar.opacity = curLay.opacity;
    fillOp (curLay.fillOpacity)
    //ayPar.fillOpacity = curLay.fillOpacity;
    layPar.blendMode = curLay.blendMode;
    curLay.opacity = 100;
    curLay.fillOpacity = 100;
    curLay.blendMode = BlendMode.NORMAL 
    }

function isArtBoard(){
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
    }; 

function fillOp(fOp){
        var idsetd = charIDToTypeID( "setd" );
        var desc18 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref1.putEnumerated( idLyr, idOrdn, idTrgt );
        desc18.putReference( idnull, ref1 );
        var idT = charIDToTypeID( "T   " );
            var desc19 = new ActionDescriptor();
            var idfillOpacity = stringIDToTypeID( "fillOpacity" );
            var idPrc = charIDToTypeID( "#Prc" );
            desc19.putUnitDouble( idfillOpacity, idPrc, fOp );
        var idLyr = charIDToTypeID( "Lyr " );
        desc18.putObject( idT, idLyr, desc19 );
    executeAction( idsetd, desc18, DialogModes.NO );
    }
Translate
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
People's Champ ,
Jan 28, 2022 Jan 28, 2022

copy layer style

goto layer set

paste layer style

goto layer

clear layer style

 

???

 

Translate
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 28, 2022 Jan 28, 2022

Nah, that's too simple... Just kidding, that is a very good suggestion!

 

I only think of layer styles when effects like drop shadow, outer glow etc. are appplied. However as you mention this works even without an effect being applied. I'll need to keep that in mind...

 

It can also be put into an action using relative keyboard shortcuts for selecting the layer and set (here presuming a single layer in the set):

 

atn.png

Translate
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
Explorer ,
Jan 29, 2022 Jan 29, 2022
LATEST

Thank you all! It worked perfectly for what I needed. And yes, some groups have more than one layer. It worked flawlessly in all possible scenarios of my work.

Translate
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