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

Opacity Scripting

Community Beginner ,
Oct 10, 2018 Oct 10, 2018

I am experimenting with scripts that can mess with changing the opacity of layers and groups. I am calling upon information from a CSV file.

I was able to change the opacity of layers using the code below:

var variable1 = docRef.artLayers.getByName("testname");

variable1.textItem.contents = content[0];

          

var variable2 = docRef.artLayers.getByName("gray");

variable2.opacity = content[1];

          

var variable3 = docRef.artLayers.getByName("scarlet");

variable3.opacity = content[2];

          

var variable4 = docRef.artLayers.getByName("white");

variable4.opacity = content[3];

But when I tried to write it to change the opacity of groups I could not get it to work. Here is what I tried:

        var variable1 = docRef.artLayers.getByName("testname");

        variable1.textItem.contents = content[0];

          

        var variable2 = docRef.layers.getByName("gray");

        variable2.opacity = content[1];

          

        var variable3 = docRef.layers.getByName("scarlet");

        variable3.opacity = content[2];

          

        var variable4 = docRef.layers.getByName("white");

        variable4.opacity = content[3];

Any help would be greatly appreciated, thanks!

TOPICS
Actions and scripting
1.9K
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
Adobe
Community Expert ,
Oct 10, 2018 Oct 10, 2018

Rather than using artLayers, just juse layers. Also you can't get nested layers with how you're doing it. You have to specify what parent group the other group is in.

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 Beginner ,
Oct 11, 2018 Oct 11, 2018

So for the example where I am trying to change the opacity of the groups, I renamed the groups to scarlet, gray & white, that is why I am still calling for those names. I also used layers to try and do it like above, but it is not working.

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
Contributor ,
Oct 11, 2018 Oct 11, 2018

var grp = app.activeDocument.layerSets.getByName("groupname");

grp.opacity = 50 // use desired number.

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 Beginner ,
Oct 11, 2018 Oct 11, 2018

Hmm, that didn't work either. Maybe it will help if I post my full script as well as show my layers so here.

var docRef = app.activeDocument;

    var dlg = new Window('dialog', 'Dataset Photomerge',[100,100,480,250]);

    dlg.btnPnl = dlg.add('panel', [25,15,365,125], 'Run Merge');

    dlg.btnPnl.testBtn = dlg.btnPnl.add('button', [15,30,305,50], 'go', {name:'ok'});

    dlg.btnPnl.testBtn.onClick = dobuild;

    dlg.show()

function dobuild() {

        dlg.close();

        var list = File("/Users/wonderly.20/Desktop/opacitytest.csv");

        list.open("r");

        var str = list.readln();

        var content = str.split(',');

        while (!list.eof) {

        str = list.readln();

        content = str.split(',');

        var variable1 = docRef.artLayers.getByName("testname");

        variable1.textItem.contents = content[0];

           

        var grp1 = docRef.layerSets.getByName("gray");

        grp1.opacity = content[1];

           

        var grp2 = docRef.layerSets.getByName("scarlet");

        grp2.opacity = content[2];

           

        var grp3 = docRef.layerSets.getByName("white");

        grp3.opacity = content[3];

        saveJPEG( app.activeDocument, new File('/Users/wonderly.20/Desktop/completed/' + 'opacitytest-' + content[0] + '.jpg'), 12 );

      }

      dlg.close();

    

     alert("All done!");

      }

    function saveJPEG( doc, saveFile, qty ) {

      var saveOptions = new JPEGSaveOptions( );

      saveOptions.embedColorProfile = true;

      saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

      saveOptions.matte = MatteType.NONE;

      saveOptions.quality = qty;

      doc.saveAs( saveFile, saveOptions, true );

    }

Screen Shot 2018-10-11 at 10.10.42 AM.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
Contributor ,
Oct 11, 2018 Oct 11, 2018

Out of curiosity, if you manually set the opacity, like below:

        var grp1 = docRef.layerSets.getByName("gray");

        grp1.opacity = 50;

Without trying to read from the CSV file, does that work?

I have done a local test without issues, however your CSV file may be causing the issue. Personally I have never used a CSV file with JS & ESTK, I prefer to use .txt docs.

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 ,
Oct 11, 2018 Oct 11, 2018

Did you use this format?

var gray = docRef.layers.getByName("gray");

docRef.activeLayer = gray;

gray.opacity = 50;

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 Beginner ,
Oct 11, 2018 Oct 11, 2018

Neither of these options worked. It is strange how I can get it to work perfectly with just changing the opacity of a layer but when I try to change the opacity of a group, it will not.

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 ,
Oct 11, 2018 Oct 11, 2018

Ummm, I'm not having any issue getting the layerrset to change. I get an error when I use artLayers rather than layers.

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 Beginner ,
Oct 11, 2018 Oct 11, 2018
LATEST

I am using layers instead of artLayers

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