Adobe color picker in dialog?

Anyone, especially newbies, asking for help with photoshop scripting and photoshop automation - as opposed to those contributing to discussion about an aspect of photoshop scripting

Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators

Adobe color picker in dialog?

Postby Mike Hale » Sat Feb 27, 2010 6:12 pm

I have this function that we came up with to use the Adobe color picker in a script. However it doesn't seem to work when used in a dialog.

Anyone have a way to have the user select a color while a dialog is open using the Adobe color picker. Or any way for that matter.

I have a dialog that has a dropdown for border colors. One of those items is 'picker...'. When the user selects that item the dialog shows a group with the backgroundcolor of that group set to black. With any other item that color group is hidden. I would like to have the user be able to choose a color which is then set to the backgroundcolor of the color group and can be used later to set the color of the image border.

Code: Select all
colorPicker();
/////////////////////////////////////////////////////////////////
// Function: colorPicker
// Description: Creates a temp solidcolor adjustment layer to
//            let the user set the forground color
//                   
// Usage: colorpicker()
// Input: None
// Return: None
// Dependencies: None
// Notes:          
//////////////////////////////////////////////////////////////////
function colorPicker(){
   // create colour layer
   CreateSolidLayer();
   // set starting color
   var startColor = app.foregroundColor;
   // call the color picker
   var desc = new ActionDescriptor();
      var ref = new ActionReference();
      ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
   desc.putReference( charIDToTypeID( "null" ), ref );
   var modeDesc = new ActionDescriptor();
      var colorDesc = new ActionDescriptor();
         colorDesc.putDouble( charIDToTypeID( "Rd  " ), startColor.rgb.red );
         colorDesc.putDouble( charIDToTypeID( "Grn " ), startColor.rgb.green );
         colorDesc.putDouble( charIDToTypeID( "Bl  " ), startColor.rgb.blue );
      modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
   desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
   executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )
   // get user's color and set to forground color
   var ref = new ActionReference();
      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   var desc = executeActionGet(ref)
   var adjList = desc.getList(stringIDToTypeID('adjustment'));
   var adjDesc = adjList.getObjectValue(0);
   var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
   var Colour = new SolidColor();
      Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
      Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
      Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
   // restore
   activeDocument.activeLayer.remove();
   app.foregroundColor = Colour;
   }

   function CreateSolidLayer() {
      var desc = new ActionDescriptor();
         var ref = new ActionReference();
         ref.putClass( stringIDToTypeID('contentLayer') );
      desc.putReference( charIDToTypeID('null'), ref );
         var desc1 = new ActionDescriptor();
            var desc2 = new ActionDescriptor();
               var desc3 = new ActionDescriptor();
               desc3.putDouble( charIDToTypeID('Rd  '), 0.000000 );
               desc3.putDouble( charIDToTypeID('Grn '), 0.000000 );
               desc3.putDouble( charIDToTypeID('Bl  '), 0.000000 );
            desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc3 );
         desc1.putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc2 );
      desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc1 );
      executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
};
Mike Hale
Site Admin
 
Posts: 4325
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Adobe color picker in dialog?

Postby ddbell » Thu Mar 01, 2012 10:45 pm

Hi Mike,

I had the same need for a color picker my latest script. I ran across your posting. I was able to modify this to work from a dialog (tested in Windows CS5).

I am doing it a little differently. My script creates a solid color layer with the opacity at zero. Then when the user clicks a button in the dialog, the solid color dialog appears for the user. The color picker works when selecting a color from the image (at least on my system).

Please excuse the bulky code. All of my functions are script listener modified code (easier for me). It seems functional though.

Code: Select all
new_adj_layer_solid (0,0,0);
layer_opacity (0);
name_layer ("Color Picker");

//dialog window
mainwindow = new Window('dialog');
mainwindow.text = 'Color Picker';

select_color_btn = mainwindow.add('button');
select_color_btn.text = 'Color Picker';
select_color_btn.onClick = function(){select_color();}

mainwindow.center();
mainwindow.show();

//functions
function select_color(){
select_layer ("Color Picker");   
update_colors(0,0,0);      
}

function select_layer (layer){
var id2299 = charIDToTypeID( "slct" );
    var desc496 = new ActionDescriptor();
    var id2300 = charIDToTypeID( "null" );
        var ref392 = new ActionReference();
        var id2301 = charIDToTypeID( "Lyr " );
        ref392.putName( id2301, layer );
    desc496.putReference( id2300, ref392 );
    var id2302 = charIDToTypeID( "MkVs" );
    desc496.putBoolean( id2302, false );
executeAction( id2299, desc496, DialogModes.NO );
   
}


function name_layer ( layername ) {
var id53 = charIDToTypeID( "setd" );
    var desc12 = new ActionDescriptor();
    var id54 = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var id55 = charIDToTypeID( "Lyr " );
        var id56 = charIDToTypeID( "Ordn" );
        var id57 = charIDToTypeID( "Trgt" );
        ref5.putEnumerated( id55, id56, id57 );
    desc12.putReference( id54, ref5 );
    var id58 = charIDToTypeID( "T   " );
        var desc13 = new ActionDescriptor();
        var id59 = charIDToTypeID( "Nm  " );
        desc13.putString( id59, layername );
    var id60 = charIDToTypeID( "Lyr " );
    desc12.putObject( id58, id60, desc13 );
executeAction( id53, desc12, DialogModes.NO );
}

function layer_opacity(pct){     
var idsetd = charIDToTypeID( "setd" );
    var desc64 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref41 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref41.putEnumerated( idLyr, idOrdn, idTrgt );
    desc64.putReference( idnull, ref41 );
    var idT = charIDToTypeID( "T   " );
        var desc65 = new ActionDescriptor();
        var idOpct = charIDToTypeID( "Opct" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc65.putUnitDouble( idOpct, idPrc, pct );
    var idLyr = charIDToTypeID( "Lyr " );
    desc64.putObject( idT, idLyr, desc65 );
executeAction( idsetd, desc64, DialogModes.NO );
}

function new_adj_layer_solid(red,green,blue){
var idMk = charIDToTypeID( "Mk  " );
    var desc22 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        ref10.putClass( idcontentLayer );
    desc22.putReference( idnull, ref10 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc23 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc24 = new ActionDescriptor();
            var idClr = charIDToTypeID( "Clr " );
                var desc25 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc25.putDouble( idRd, red );
                var idGrn = charIDToTypeID( "Grn " );
                desc25.putDouble( idGrn, green );
                var idBl = charIDToTypeID( "Bl  " );
                desc25.putDouble( idBl, blue );
            var idRGBC = charIDToTypeID( "RGBC" );
            desc24.putObject( idClr, idRGBC, desc25 );
        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
        desc23.putObject( idType, idsolidColorLayer, desc24 );
    var idcontentLayer = stringIDToTypeID( "contentLayer" );
    desc22.putObject( idUsng, idcontentLayer, desc23 );
executeAction( idMk, desc22, DialogModes.NO );
}

function update_colors(red,green,blue){
var idsetd = charIDToTypeID( "setd" );
    var desc13 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref6 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref6.putEnumerated( idcontentLayer, idOrdn, idTrgt );
    desc13.putReference( idnull, ref6 );
    var idT = charIDToTypeID( "T   " );
        var desc14 = new ActionDescriptor();
        var idClr = charIDToTypeID( "Clr " );
            var desc15 = new ActionDescriptor();
            var idRd = charIDToTypeID( "Rd  " );
            desc15.putDouble( idRd, red );
            var idGrn = charIDToTypeID( "Grn " );
            desc15.putDouble( idGrn, green );
            var idBl = charIDToTypeID( "Bl  " );
            desc15.putDouble( idBl, blue );
        var idRGBC = charIDToTypeID( "RGBC" );
        desc14.putObject( idClr, idRGBC, desc15 );
    var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
    desc13.putObject( idT, idsolidColorLayer, desc14 );
executeAction( idsetd, desc13, DialogModes.ALL );

var ref = new ActionReference();
      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   var desc = executeActionGet(ref)
   var adjList = desc.getList(stringIDToTypeID('adjustment'));
   var adjDesc = adjList.getObjectValue(0);
   var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
   var Colour = new SolidColor();
      Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
      Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
      Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));

alert (Colour.rgb.red);
alert (Colour.rgb.green);
alert (Colour.rgb.blue);
    
}


ddbell
 
Posts: 126
Joined: Sun Jun 07, 2009 7:39 pm

Re: Adobe color picker in dialog?

Postby ddbell » Thu Mar 01, 2012 11:19 pm

I just realized that this only works with the color picker option set to "sample all layers". Hopefully there is a way to script this to setting. I'll post how to do this if I can figure out how to do this. If anyone knows how to do this then feel free to reply.
ddbell
 
Posts: 126
Joined: Sun Jun 07, 2009 7:39 pm

Re: Adobe color picker in dialog?

Postby Paul MR » Fri Mar 02, 2012 9:18 am

I have a colour picker in this script Mike, it lets you set the colour within the UI.
Shift key required to get the UI.
Hope this is near...

Edit.. Sorry it's a two year old post!
Never mind the the script might be of use to some.
Attachments
WaterMarkCS5.zip
(4.77 KiB) Downloaded 63 times
Paul MR
 
Posts: 1472
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Re: Adobe color picker in dialog?

Postby ddbell » Fri Mar 02, 2012 4:27 pm

Hi Paul,

Do you know if the eye dropper settings can be scripted to sample all layers? I have not figured out if this can be done.

I have a script which is meant for the user to sample a color from the image itself. It uses a solid color layer similar to your script. The solid color layer is set with the opacity at zero so you just see the image below the solid color layer. The color picker works fine to sample colors from the image. The only issue is if the eye dropper tool is set to sample current layer. In this case, it won't sample from the image below the solid color layer. The eye dropper needs to be set to sample all layers. I'd like to have the script just set it to this setting. However, I'm not sure if it can be done.
ddbell
 
Posts: 126
Joined: Sun Jun 07, 2009 7:39 pm

Re: Adobe color picker in dialog?

Postby Mike Hale » Fri Mar 02, 2012 4:55 pm

'Sample All Layers' for the eye dropper tool, like almost all other tool options, can only be set with a script by using tool presets. A script can get a tool's options without much trouble but setting them requires using presets.
Mike Hale
Site Admin
 
Posts: 4325
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Adobe color picker in dialog?

Postby ddbell » Fri Mar 02, 2012 5:35 pm

OK, thanks. A preset should work out fine for my needs.
ddbell
 
Posts: 126
Joined: Sun Jun 07, 2009 7:39 pm

Re: Adobe color picker in dialog?

Postby ddbell » Fri Mar 02, 2012 11:09 pm

Well, I guess there is something buggy going on which is why this was posted in the 1st place. Last night I tested this in CS3 and CS5 and the eyedropper was working with the dialog window open. Now it stopped working in both CS3 and CS5. I have not made any changes to the script or to either versions of Photoshop. I rebooted the PC and it still doesn't work. I just get a mouse cursor instead of the eyedropper. Bummer.............

If I figure out what toggles it I'll post it.
ddbell
 
Posts: 126
Joined: Sun Jun 07, 2009 7:39 pm


Return to Help Me

Who is online

Users browsing this forum: No registered users and 2 guests