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

Set opacity of particular layer

Enthusiast ,
Feb 04, 2016 Feb 04, 2016

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 );

TOPICS
Actions and scripting
594
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 1 Correct answer

Community Expert , Feb 04, 2016 Feb 04, 2016

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.

Translate
Adobe
Community Expert ,
Feb 04, 2016 Feb 04, 2016

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.

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
Enthusiast ,
Feb 04, 2016 Feb 04, 2016
LATEST

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?

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