Copy link to clipboard
Copied
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!
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
...
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
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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"));
};
Copy link to clipboard
Copied
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"));
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Why to comment commands which explicitly say themselves their function? 😕
Copy link to clipboard
Copied
As searchable keywords when I am trawling through my script collection folder looking to reuse code.
Copy link to clipboard
Copied
If your folder is outside then these codes over here can be free of personal comments.
Copy link to clipboard
Copied
I'll give your suggestion all of the consideration that it deserves.
Copy link to clipboard
Copied
And how much of consideration that suggestion deserves? 😛
Copy link to clipboard
Copied
😛
Copy link to clipboard
Copied
Meet me half way... I'll remove comments from my code if you add comments into your code postings! 😉
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Umm, I thought the fill opacity was working on the layerset I guess I'll have to double check.
Copy link to clipboard
Copied
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 );
}
Copy link to clipboard
Copied
copy layer style
goto layer set
paste layer style
goto layer
clear layer style
???
Copy link to clipboard
Copied
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):
Copy link to clipboard
Copied
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.