Skip to main content
Inspiring
April 6, 2018
Answered

Dialog box with check boxes in Photoshop CS6, javascript

  • April 6, 2018
  • 2 replies
  • 3511 views

Hi,

I need to create dialog box to allow user to pick from selection of check boxes in Photoshop CS6, javascript.

Thank you.

Yulia

This topic has been closed for replies.
Correct answer SuperMerlin

Thank you, this is great. Will it allow the user to choose more than one color at the time?

Yulia


No this example is only one colour at a time.

This will let you use 3.

#target photoshop

app.bringToFront();

main();

function main(){

if(!documents.length) {

    alert("No documents are open!");

    return;

    }

var win = new Window('dialog','Spot Channel');

win.orientation='column';

win.alignChildren = 'center';

win.pnl1 = win.add('panel',undefined,'Spot Channel', {borderStyle: 'black'} );

win.pnl1.alignChildren = 'left';

win.pnl1.rb1 = win.pnl1.add('checkbox',undefined,'Colour 1');

win.pnl1.rb1.value=true;

win.pnl1.rb2 = win.pnl1.add('checkbox',undefined,'Colour 2');

win.pnl1.rb3 = win.pnl1.add('checkbox',undefined,'Colour 3');

win.grp1 = win.add('group');

win.select = win.grp1.add('button',undefined,'Ok');

win.can = win.grp1.add('button',undefined,'Cancel');

win.select.preferredSize = win.can.preferredSize=[70,20];

win.select.onClick=function(){

win.close(0);

if(win.pnl1.rb1.value){

   //Checkbox 1

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 0; 

theColor.cmyk.yellow = 0; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test1"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();  

}

if(win.pnl1.rb2.value){

   //Checkbox 2

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 0; 

theColor.cmyk.yellow = 50; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test2"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();

}

if(win.pnl1.rb3.value){

   //Checkbox 3

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 50; 

theColor.cmyk.yellow = 0; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test3"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();

}

}

win.center();

win.show();

}

 

2 replies

JJMack
Adobe Expert
April 7, 2018

You code Dialog using  Adobe ScriptUI.  The documentation is in the manual JavaScript-Tools-Guide-CC.pdf

JJMack
JJMack
Adobe Expert
April 6, 2018

ScriptUI supports check boxes and radio buttons. Can you  elaborate about what you mean pick from a selection of check boxes. A user can select more than one check box  where selecting one radio button turns off other radio buttons in a in its group.

JJMack
Inspiring
April 6, 2018

Yes, I need user to be able to make multiple selections.

SuperMerlin
SuperMerlinCorrect answer
Inspiring
April 7, 2018

Thank you, this is great. Will it allow the user to choose more than one color at the time?

Yulia


No this example is only one colour at a time.

This will let you use 3.

#target photoshop

app.bringToFront();

main();

function main(){

if(!documents.length) {

    alert("No documents are open!");

    return;

    }

var win = new Window('dialog','Spot Channel');

win.orientation='column';

win.alignChildren = 'center';

win.pnl1 = win.add('panel',undefined,'Spot Channel', {borderStyle: 'black'} );

win.pnl1.alignChildren = 'left';

win.pnl1.rb1 = win.pnl1.add('checkbox',undefined,'Colour 1');

win.pnl1.rb1.value=true;

win.pnl1.rb2 = win.pnl1.add('checkbox',undefined,'Colour 2');

win.pnl1.rb3 = win.pnl1.add('checkbox',undefined,'Colour 3');

win.grp1 = win.add('group');

win.select = win.grp1.add('button',undefined,'Ok');

win.can = win.grp1.add('button',undefined,'Cancel');

win.select.preferredSize = win.can.preferredSize=[70,20];

win.select.onClick=function(){

win.close(0);

if(win.pnl1.rb1.value){

   //Checkbox 1

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 0; 

theColor.cmyk.yellow = 0; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test1"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();  

}

if(win.pnl1.rb2.value){

   //Checkbox 2

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 0; 

theColor.cmyk.yellow = 50; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test2"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();

}

if(win.pnl1.rb3.value){

   //Checkbox 3

var theColor = new SolidColor(); 

theColor.cmyk.cyan = 50; 

theColor.cmyk.magenta = 50; 

theColor.cmyk.yellow = 0; 

theColor.cmyk.black = 0; 

var theCh = activeDocument.channels.add(); 

theCh.kind = ChannelType.SPOTCOLOR; 

theCh.name = "test3"; 

theCh.opacity = 50; 

theCh.color = theColor;   

activeDocument.activeLayer.invert();

}

}

win.center();

win.show();

}