Copy link to clipboard
Copied
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?

// 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
...Copy link to clipboard
Copied
// 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
dlg.layer.add('scrollbar', undefined, theLayers
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
};
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 );
};
Copy link to clipboard
Copied
Big
Thanks just what I needed
friendly
happy 2016
Copy link to clipboard
Copied
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();
};
Copy link to clipboard
Copied
Good morning and thank you,
I noticed that the levels are proposed to me on the contrary
you can modify them to see properly.

the second script does not go on my mac.
Copy link to clipboard
Copied
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%:

Copy link to clipboard
Copied
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.

Copy link to clipboard
Copied
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.

Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok
Thanks for all.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
No the produced an undefined error.
However changing
for (var m = 0; m <= theNumber; m++) {
to
for (var m = theNumber; m >= 0; m--) {
Works
Copy link to clipboard
Copied
I put the string you sent me it by always error

Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I had a hang (in 2015.1.1) with the Script, too, recently.
I wonder if $.gc() in the inChange function might help …
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You are right, that’s garbage collection.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Its a good script to experiment with. I can hang cc 2015 at will with it.
Copy link to clipboard
Copied
I can hang cc 2015 at will with it.
Which step/s cause the hang?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.

Find more inspiration, events, and resources on the new Adobe Community
Explore Now