Skip to main content
Participant
October 31, 2013
Question

How to change a layers opacity?

  • October 31, 2013
  • 1 reply
  • 935 views

Hi there,

I am new to the whole concept of photoshop cripting and am really struggling,  I wish to change the opacity of several layers, do I have to define the function first??

I would really appreciate it if someone could help!! realy struggling here

This topic has been closed for replies.

1 reply

Inspiring
October 31, 2013

The opacity of a layer is changed by setting the layer object's opacity property

app.activeDocument.activeLayer.opacity = 50;

You can only set the opacity one layer at a time so if you want to change several layers you will need to change them one at a time.

You do not have to have a function or other control structures like a loop but depending on what else you want to do or coding style them could be helpful.

caillteAuthor
Participant
October 31, 2013

so I just have it in the wrong place? sorry.. im really stuck here  

                    app.activeDocument=doc1;

                    doc1.resizeImage(posterWidth,posterHeight/4);

                    doc1.selection.selectAll();

                    doc1.selection.copy();

                    doc1.selection.deselect();

                    app.activeDocument=newDoc;

                    newDoc.artLayers.add();

                    newDoc.paste();

                    newDoc.activeLayer.translate(0,-posterHeight/2+posterHeight/8);

                    app.activeDocument=newDoc;

                    newDoc.selection.selectAll();

                    newDoc.selection.opacity = 17;

                    newDoc.selection.deselect();

pixxxelschubser
Community Expert
Community Expert
October 31, 2013

Not yet the correct syntax.

Try something like this (look to compare):

var doc1 = app.activeDocument;

var h = doc1.height ;

var w = doc1.width;

doc1.resizeImage (w, h/4);

doc1.selection.selectAll();

doc1.selection.copy();

doc1.selection.deselect(); // do never save your doc1 at this time !!!

var newDoc = app.documents.add ();

newDoc.paste();

newDoc.activeLayer.translate (0, -h/2+h/8);

newDoc.activeLayer.opacity = 17;

app.refresh();