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

change opacity levels individually

Contributor ,
Jan 01, 2016 Jan 01, 2016

Good year

I'm new to scripting and speak little English I hope to be clear.

I would like to create a panel that I change the opacity levels individually

as in this example

second and you can make it happen?

Schermata 2016-01-01 alle 12.11.44.png

TOPICS
Actions and scripting
3.8K
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 , Jan 02, 2016 Jan 02, 2016

// change layers’ opacity via scrollbars;

// 2015, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

app.activeDocument.suspendHistory("opacity", "theDialog ()");

};

function theDialog () {

//////////////////////////////////////////

var theLayers = theLayerNames ();

////// create dialog for user-entry //////

var dlg = new Window('dialog', "layeropacity", undefined);

//////////////////////////////

dlg.layer = dlg.add('panel', undefined, "opacity");

dlg.layer.orientation = "column";

dlg

...
Translate
Adobe
Community Expert ,
Jan 02, 2016 Jan 02, 2016

// change layers’ opacity via scrollbars;

// 2015, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

app.activeDocument.suspendHistory("opacity", "theDialog ()");

};

function theDialog () {

//////////////////////////////////////////

var theLayers = theLayerNames ();

////// create dialog for user-entry //////

var dlg = new Window('dialog', "layeropacity", undefined);

//////////////////////////////

dlg.layer = dlg.add('panel', undefined, "opacity");

dlg.layer.orientation = "column";

dlg.layer.preferredSize = [300, 50];

// populate panel;

for (var m = 0; m < theLayers.length; m++) {

dlg.layer.add('statictext', undefined, theLayers[0]);

dlg.layer.add('scrollbar', undefined, theLayers[2], 0, 255);

dlg.layer.children[m*2+1].preferredSize = [255,20];

//////////////////////////////

// if scrolled;

dlg.layer.children[m*2+1].onChange = function () {

var theCh = dlg.layer.children.length;

for (var n = 0; n < theCh; n++) {

  if (dlg.layer.children == this) {var theNumber = n}

  };

setOpacityByID (theLayers[(theNumber-1)/2][1], Math.round(this.value));

app.refresh();

};

};

//////////////////////////////

// build- and cancel-button;

dlg.cancelOk = dlg.add('panel', [12,495,308,550], "");

dlg.cancelOk.buildBtn = dlg.cancelOk.add('button', [10,10,141,40], 'OK', {name:'ok'});

dlg.cancelOk.cancelBtn = dlg.cancelOk.add('button', [149,10,280,40], 'Cancel', {name:'cancel'});

dlg.center();

var myReturn = dlg.show ();

//////////////////////////////

// reset if canceled;

if (myReturn != 1) {

for (var a = 0; a < theLayers.length; a++) {

setOpacityByID (theLayers[1], theLayers[2])

}

};

$.gc();

};

////////////////////////////////////

function theLayerNames () {

// the file;

var myDocument = app.activeDocument;

// get number of layers;

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var applicationDesc = executeActionGet(ref);

var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

// process the layers;

var theLayers = new Array;

for (var m = 0; m <= theNumber; m++) {

try {

var ref = new ActionReference();

ref.putIndex( charIDToTypeID( "Lyr " ), m);

var layerDesc = executeActionGet(ref);

var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

// if not layer group collect values;

if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {

var theName = layerDesc.getString(stringIDToTypeID('name'));

var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

var theOpacity = layerDesc.getInteger(stringIDToTypeID('opacity'));

theLayers.push([theName, theID, theOpacity])

};

}

catch (e) {};

};

return theLayers

};

////// set opacity //////

function setOpacityByID (theID, theOpacity) {

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    var idLyr = charIDToTypeID( "Lyr " );

        var ref1 = new ActionReference();

        ref1.putIdentifier( idLyr, theID );

    desc2.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var desc3 = new ActionDescriptor();

        desc3.putUnitDouble( charIDToTypeID( "Opct" ), charIDToTypeID( "#Prc" ), Math.round(theOpacity/2.55) );

    desc2.putObject( idT, idLyr, desc3 );

executeAction( idsetd, desc2, DialogModes.NO );

};

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 ,
Jan 02, 2016 Jan 02, 2016

Big

Thanks just what I needed

friendly

happy 2016

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 ,
Jan 03, 2016 Jan 03, 2016

It may be a dubious improvement, but you could replace the function theDialog with this, it saves a few lines:

function theDialog () {

//////////////////////////////////////////

var theLayers = theLayerNames ();

////// create dialog for user-entry //////

var dlg = new Window('dialog', "layeropacity", undefined);

//////////////////////////////

dlg.layer = dlg.add('panel', undefined, "opacity");

dlg.layer.orientation = "column";

dlg.layer.preferredSize = [300, 50];

// populate panel;

for (var m = 0; m < theLayers.length; m++) {

dlg.layer.add('statictext', undefined, theLayers[0]);

dlg.layer.add('scrollbar', undefined, theLayers[2], 0, 255);

dlg.layer.children[m*2+1].preferredSize = [256,20];

dlg.layer.children[m*2+1].helpTip = String(m);

//////////////////////////////

// if scrolled;

dlg.layer.children[m*2+1].onChange = function () {

setOpacityByID (theLayers[Number(this.helpTip)][1], Math.round(this.value));

app.refresh();

};

};

//////////////////////////////

// build- and cancel-button;

dlg.cancelOk = dlg.add('panel', [12,495,308,550], "");

dlg.cancelOk.buildBtn = dlg.cancelOk.add('button', [10,10,141,40], 'OK', {name:'ok'});

dlg.cancelOk.cancelBtn = dlg.cancelOk.add('button', [149,10,280,40], 'Cancel', {name:'cancel'});

dlg.center();

var myReturn = dlg.show ();

//////////////////////////////

// reset if canceled;

if (myReturn != 1) {

for (var a = 0; a < theLayers.length; a++) {

setOpacityByID (theLayers[1], theLayers[2])

}

};

$.gc();

};

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 ,
Jan 03, 2016 Jan 03, 2016

Good morning and thank you,

I noticed that the levels are proposed to me on the contrary

you can modify them to see properly.

Schermata 2016-01-03 alle 11.45.38.png

the second script does not go on my mac.

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 ,
Jan 03, 2016 Jan 03, 2016

Post 3 did not contain the complete Script but only the one function.

I noticed that the levels are proposed to me on the contrary

What do you mean?

Which Photoshop version do you use?

For me the dialog looks like this and the left of the scrollbar represents 0%, the right 100%:

layerOpacityScr.jpg

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 ,
Jan 03, 2016 Jan 03, 2016

Viewing screenshot

you too are on the contrary

use photoshop cc2014

excuse the panel used by you and much more 'nice

can I have it.

layerOpacityScr copia.jpg

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 ,
Jan 03, 2016 Jan 03, 2016

Whatever you do do not try the script with CC 2015 I found playing with a slider cause CC 2015 to loop be not responsive had to terminate CC 2015 with Windows Task Manager.

Capture.jpg

JJMack
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 ,
Jan 03, 2016 Jan 03, 2016
I found playing with a slider cause CC 2015 to loop be not responsive had to terminate CC 2015 with Windows Task Manager

I use Photoshop CC 2015.1.1 on Mac OS X 10.9.5 and it seems to work fine.

Did you use the original one or did you replace the function theDialog with the amended one?

you too are on the contrary

Once again: What do you mean?

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 ,
Jan 04, 2016 Jan 04, 2016

c.pfaffenbichler

Thanks for the time you gave me

I use cc2014 on mac and the slider works perfectly

how to make buttons cancel and ok like your.

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 ,
Jan 04, 2016 Jan 04, 2016
how to make buttons cancel and ok like your.

I’m afraid the appearance is a Script UI matter and dependent on the version of Photoshop/ExtendScript one uses, they just look like that in the most current version.

It might be possible to simulate the appearance in older versions by using graphics in the dialog but it does not seem worth the trouble.

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 ,
Jan 04, 2016 Jan 04, 2016

Ok

Thanks for all.

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 ,
Jan 04, 2016 Jan 04, 2016
you too are on the contrary

Now I understand … changing the line

for (var m = 0; m < theLayers.length; m++) {

to

for (var m = theLayers.length-1; m >= 0; m--) {

should invert the order of the layers in the dialog.

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 ,
Jan 04, 2016 Jan 04, 2016

No the produced an undefined error.

However changing

for (var m = 0; m <= theNumber; m++) {


to

for (var m = theNumber; m >= 0; m--) {

Works

JJMack
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 ,
Jan 04, 2016 Jan 04, 2016

I put the string you sent me it by always error

Schermata 2016-01-04 alle 14.55.44.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
Community Expert ,
Jan 04, 2016 Jan 04, 2016

Here is his latest Script with his mod to  change the order of the sliders to match the layers palette..

http://www.mouseprints.net/old/dpr/LayerOpacityScrollBars.jsx

CC 2015 ScriptUI hang on my Windows 10 system with this script when you play with the sliders I use CC 2014.

JJMack
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 ,
Jan 04, 2016 Jan 04, 2016

I had a hang (in 2015.1.1) with the Script, too, recently.

I wonder if $.gc() in the inChange function might help …

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 ,
Jan 04, 2016 Jan 04, 2016

As I only hack at scripting  I do not even know what  $.gc() is about. Garbish Collection?? Could you shed some light I was intending to look at documentation.

JJMack
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 ,
Jan 04, 2016 Jan 04, 2016

You are right, that’s garbage collection.

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 ,
Jan 04, 2016 Jan 04, 2016

I downloaded the script of Mr. JJ Mack

and it works well on cc2014mac

I cancellalto this $ .gc (); and the script works well

I sincerely thank you both for the help.

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 ,
Jan 04, 2016 Jan 04, 2016

Its a good script to experiment with. I can hang cc 2015 at will with it.

JJMack
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 ,
Jan 04, 2016 Jan 04, 2016
I can hang cc 2015 at will with it.

Which step/s cause the hang?

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 ,
Jan 04, 2016 Jan 04, 2016

ALL I need to do is drag a slider about  without letting the mouse bottom go. Soon both arrows on the scroll bar are gone soon the task manager shows Photoshop is not responding. Photoshop exe is still getting cpu but has to be terminated using the task manager

JJMack
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 ,
Jan 05, 2016 Jan 05, 2016

JJMack, could you try with this dialog-function?

function theDialog () {

//////////////////////////////////////////

var theLayers = theLayerNames ();

////// create dialog for user-entry //////

var dlg = new Window('dialog', "layeropacity", undefined);

//////////////////////////////

dlg.layer = dlg.add('panel', undefined, "opacity");

dlg.layer.orientation = "column";

dlg.layer.preferredSize = [300, 50];

// populate panel;

//for (var m = 0; m < theLayers.length; m++) {

for (var m = theLayers.length-1; m >= 0; m--) {

dlg.layer.add('statictext', undefined, theLayers[0]);

dlg.layer.add('scrollbar', undefined, theLayers[2], 0, 255);

var thisIndex = dlg.layer.children.length - 1;

dlg.layer.children[thisIndex].preferredSize = [256,20];

dlg.layer.children[thisIndex].helpTip = String(m);

//////////////////////////////

// if scrolled;

dlg.layer.children[thisIndex].onChange = function () {

setOpacityByID (theLayers[Number(this.helpTip)][1], Math.round(this.value));

app.refresh();

$.gc();

};

};

//////////////////////////////

// build- and cancel-button;

dlg.cancelOk = dlg.add('panel', [12,495,308,550], "");

dlg.cancelOk.buildBtn = dlg.cancelOk.add('button', [10,10,141,40], 'OK', {name:'ok'});

dlg.cancelOk.cancelBtn = dlg.cancelOk.add('button', [149,10,280,40], 'Cancel', {name:'cancel'});

dlg.center();

var myReturn = dlg.show ();

//////////////////////////////

// reset if canceled;

if (myReturn != 1) {

for (var a = 0; a < theLayers.length; a++) {

setOpacityByID (theLayers[1], theLayers[2])

}

};

$.gc();

};

The difference is the $.gc() in the onChange function – not sure it makes a difference, but so far I have not been able to create a hang with this.

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 ,
Jan 05, 2016 Jan 05, 2016

I had tries putting garbage collection in the onChange function when you made the other append. It made no difference the arrows go away Photoshop loops and does not respond to user action has to be terminated using Task Manager.

Capture.jpg

JJMack
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