Copy link to clipboard
Copied
Hi, I have a layer named 'concrete' and I'm trying to adjust its opacity to 50% in a script. Problem is, this script adjusts the active layer's opacity, not the layer named 'concrete'. So in other words the active layer might be 'Layer 12', and somewhere else in the layer stack is the layer named 'concrete'. I want to adjust its opacity to 50% without having to switch over to the 'concrete' layer, manually adjust the opacity, and then switch back to 'layer 12'. I was hoping a script could just change it automatically. Here's what I have so far, I'm hoping someone might suggest a tweak to get it working:
#target photoshop
var layerRef = app.activeDocument.layers.getByName( 'concrete' );
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc9657 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2889 = new ActionReference();
var idLyr = app.activeDocument.layers.getByName( 'concrete texture' )( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref2889.putEnumerated( idLyr, idOrdn, idTrgt );
desc9657.putReference( idnull, ref2889 );
var idT = charIDToTypeID( "T " );
var desc9658 = new ActionDescriptor();
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc9658.putUnitDouble( idOpct, idPrc, 50.000000 );
var idLyr = charIDToTypeID( "Lyr " );
desc9657.putObject( idT, idLyr, desc9658 );
executeAction( idsetd, desc9657, DialogModes.NO );
You seem to mix DOM and AM code.
A simple
app.activeDocument.layers.getByName( 'concrete' ).opacity = 50;
should suffice if the Layer named "concrete" is at the top-level and not in a group.
Copy link to clipboard
Copied
You seem to mix DOM and AM code.
A simple
app.activeDocument.layers.getByName( 'concrete' ).opacity = 50;
should suffice if the Layer named "concrete" is at the top-level and not in a group.
Copy link to clipboard
Copied
wow, thanks - I had no idea it was that easy. How about if the 'concrete' layer was indeed inside a group - does it make things more complicated?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now