Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
var grp = app.activeDocument.layerSets.getByName("groupname");
grp.opacity = 50 // use desired number.
Copy link to clipboard
Copied
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 );
}

Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Did you use this format?
var gray = docRef.layers.getByName("gray");
docRef.activeLayer = gray;
gray.opacity = 50;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ummm, I'm not having any issue getting the layerrset to change. I get an error when I use artLayers rather than layers.
Copy link to clipboard
Copied
I am using layers instead of artLayers
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more