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

How to access the "Color Picker (Stroke Color)" window as a jsx?

Engaged ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Hello! I am studying User Interface and I need to create an event for a button that will give the user an option to change the stroke color of a Stylo layer with an applied stroke applied. How can I access the Color Picker window "Stroke Color" without the need to open the "Layer Style" window through a script?

CAPA.jpg

It would look something like this:

var color = $.colorPicker (); 

alert(color);

TOPICS
Actions and scripting

Views

2.0K

Translate

Translate

Report

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 , Mar 17, 2017 Mar 17, 2017

You would need to add another button to close the ui and a refresh statement after you select the color.

#target Photoshop

var doc = activeDocument;

var dlg = new Window('dialog','Set Stroke Color');

    dlg.strokeBtn = dlg.add('button',undefined,'Set Stroke Color');

    dlg.ok = dlg.add('button',undefined,'Okay');

   

    dlg.strokeBtn.onClick = function(){

        getColor ()

        app.refresh()

        }

    dlg.ok.onClick = function(){dlg.close()}

    dlg.show()

   

function getColor(){

     var cP =

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

$.colorPicker() will bring up the system color picker. A workaround would be to bring up the PS color picker, set the foreground color, then use those value to set the stroke color:

var cP = showColorPicker()

if(cP){

    var r = foregroundColor.rgb.red

    var g = foregroundColor.rgb.green

    var b = foregroundColor.rgb.blue   

    alert('red = ' + r + ' green =' + g + ' blue = ' + b)

    }

Votes

Translate

Translate

Report

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
Engaged ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

And how do we actually run scripts? Do you mind sharing a simple example? Any help is important.

I believe you are referring only to layers with shapes.

Remembering this would have to work on any layer since there is a stroke (Styles) through the "Color Picker (Stroke Color)". Thank you!

Votes

Translate

Translate

Report

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 ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

To run a script, you would save the code as a plain text file, with a jsx extension, place it in the Presets/Scripts folder. As far as a sample, here's simple script with a UI, that has a button to bring up the color picker, that will then create a stroke in that color. The code for setting the stroke was made by using the scriptlistener plugin. then you just find the values you want to change, and insert a variable in those places.

#target Photoshop

var doc = activeDocument;

var dlg = new Window('dialog','Set Stroke Color');

    dlg.strokeBtn = dlg.add('button',undefined,'Set Stroke Color');

   

    dlg.strokeBtn.onClick = function(){

        dlg.close()

        getColor ()

        }

   

    dlg.show()

   

function getColor(){

     var cP = showColorPicker() 

        if(cP){ 

            var r = foregroundColor.rgb.red 

            var g = foregroundColor.rgb.green 

            var b = foregroundColor.rgb.blue     

             makeStoke (r, g, b)

            }     

     }

function makeStoke(redC,greenC,blueC)   {

    var idsetd = charIDToTypeID( "setd" );

        var desc6 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idLefx = charIDToTypeID( "Lefx" );

            ref1.putProperty( idPrpr, idLefx );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idLyr, idOrdn, idTrgt );

        desc6.putReference( idnull, ref1 );

        var idT = charIDToTypeID( "T   " );

            var desc7 = new ActionDescriptor();

            var idScl = charIDToTypeID( "Scl " );

            var idPrc = charIDToTypeID( "#Prc" );

            desc7.putUnitDouble( idScl, idPrc, 416.666667 );

            var idFrFX = charIDToTypeID( "FrFX" );

                var desc8 = new ActionDescriptor();

                var idenab = charIDToTypeID( "enab" );

                desc8.putBoolean( idenab, true );

                var idpresent = stringIDToTypeID( "present" );

                desc8.putBoolean( idpresent, true );

                var idshowInDialog = stringIDToTypeID( "showInDialog" );

                desc8.putBoolean( idshowInDialog, true );

                var idStyl = charIDToTypeID( "Styl" );

                var idFStl = charIDToTypeID( "FStl" );

                var idOutF = charIDToTypeID( "OutF" );

                desc8.putEnumerated( idStyl, idFStl, idOutF );

                var idPntT = charIDToTypeID( "PntT" );

                var idFrFl = charIDToTypeID( "FrFl" );

                var idSClr = charIDToTypeID( "SClr" );

                desc8.putEnumerated( idPntT, idFrFl, idSClr );

                var idMd = charIDToTypeID( "Md  " );

                var idBlnM = charIDToTypeID( "BlnM" );

                var idNrml = charIDToTypeID( "Nrml" );

                desc8.putEnumerated( idMd, idBlnM, idNrml );

                var idOpct = charIDToTypeID( "Opct" );

                var idPrc = charIDToTypeID( "#Prc" );

                desc8.putUnitDouble( idOpct, idPrc, 100.000000 );

                var idSz = charIDToTypeID( "Sz  " );

                var idPxl = charIDToTypeID( "#Pxl" );

                desc8.putUnitDouble( idSz, idPxl, 250.000000 );

                var idClr = charIDToTypeID( "Clr " );

                    var desc9 = new ActionDescriptor();

                    var idRd = charIDToTypeID( "Rd  " );

                    //desc9.putDouble( idRd, 229.000002 );  original line

                    desc9.putDouble( idRd, redC );

                    var idGrn = charIDToTypeID( "Grn " );

                    //desc9.putDouble( idGrn, 17.062257 );   original line

                    desc9.putDouble( idGrn, greenC );

                    var idBl = charIDToTypeID( "Bl  " );

                    //desc9.putDouble( idBl, 17.062257 );   original line

                    desc9.putDouble( idBl, blueC );

                var idRGBC = charIDToTypeID( "RGBC" );

                desc8.putObject( idClr, idRGBC, desc9 );

                var idoverprint = stringIDToTypeID( "overprint" );

                desc8.putBoolean( idoverprint, false );

            var idFrFX = charIDToTypeID( "FrFX" );

            desc7.putObject( idFrFX, idFrFX, desc8 );

        var idLefx = charIDToTypeID( "Lefx" );

        desc6.putObject( idT, idLefx, desc7 );

    executeAction( idsetd, desc6, DialogModes.NO );

}

Votes

Translate

Translate

Report

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
Engaged ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Wow! Chuck Uebele you work as a true genius. Congratulations! Now I'll just set a smaller value for the size and switch the position from external to internal. Thank you for sharing your knowledge.

Votes

Translate

Translate

Report

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
Engaged ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Here I was doing pretty well until I realized that the selected color only applies when the dlg.show () window is closed. Chuck Uebele  Is there a possibility to apply (show) the change before the Window closes, and how would it be? Is this related to the variable you are referring to? Thank you.

Votes

Translate

Translate

Report

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

You would need to add another button to close the ui and a refresh statement after you select the color.

#target Photoshop

var doc = activeDocument;

var dlg = new Window('dialog','Set Stroke Color');

    dlg.strokeBtn = dlg.add('button',undefined,'Set Stroke Color');

    dlg.ok = dlg.add('button',undefined,'Okay');

   

    dlg.strokeBtn.onClick = function(){

        getColor ()

        app.refresh()

        }

    dlg.ok.onClick = function(){dlg.close()}

    dlg.show()

   

function getColor(){

     var cP = showColorPicker() 

        if(cP){ 

            var r = foregroundColor.rgb.red 

            var g = foregroundColor.rgb.green 

            var b = foregroundColor.rgb.blue     

             makeStoke (r, g, b)

            }     

     }

function makeStoke(redC,greenC,blueC)   {

    var idsetd = charIDToTypeID( "setd" );

        var desc6 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idLefx = charIDToTypeID( "Lefx" );

            ref1.putProperty( idPrpr, idLefx );

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idLyr, idOrdn, idTrgt );

        desc6.putReference( idnull, ref1 );

        var idT = charIDToTypeID( "T   " );

            var desc7 = new ActionDescriptor();

            var idScl = charIDToTypeID( "Scl " );

            var idPrc = charIDToTypeID( "#Prc" );

            desc7.putUnitDouble( idScl, idPrc, 416.666667 );

            var idFrFX = charIDToTypeID( "FrFX" );

                var desc8 = new ActionDescriptor();

                var idenab = charIDToTypeID( "enab" );

                desc8.putBoolean( idenab, true );

                var idpresent = stringIDToTypeID( "present" );

                desc8.putBoolean( idpresent, true );

                var idshowInDialog = stringIDToTypeID( "showInDialog" );

                desc8.putBoolean( idshowInDialog, true );

                var idStyl = charIDToTypeID( "Styl" );

                var idFStl = charIDToTypeID( "FStl" );

                var idOutF = charIDToTypeID( "OutF" );

                desc8.putEnumerated( idStyl, idFStl, idOutF );

                var idPntT = charIDToTypeID( "PntT" );

                var idFrFl = charIDToTypeID( "FrFl" );

                var idSClr = charIDToTypeID( "SClr" );

                desc8.putEnumerated( idPntT, idFrFl, idSClr );

                var idMd = charIDToTypeID( "Md  " );

                var idBlnM = charIDToTypeID( "BlnM" );

                var idNrml = charIDToTypeID( "Nrml" );

                desc8.putEnumerated( idMd, idBlnM, idNrml );

                var idOpct = charIDToTypeID( "Opct" );

                var idPrc = charIDToTypeID( "#Prc" );

                desc8.putUnitDouble( idOpct, idPrc, 100.000000 );

                var idSz = charIDToTypeID( "Sz  " );

                var idPxl = charIDToTypeID( "#Pxl" );

                desc8.putUnitDouble( idSz, idPxl, 250.000000 );

                var idClr = charIDToTypeID( "Clr " );

                    var desc9 = new ActionDescriptor();

                    var idRd = charIDToTypeID( "Rd  " );

                    //desc9.putDouble( idRd, 229.000002 );  original line

                    desc9.putDouble( idRd, redC );

                    var idGrn = charIDToTypeID( "Grn " );

                    //desc9.putDouble( idGrn, 17.062257 );   original line

                    desc9.putDouble( idGrn, greenC );

                    var idBl = charIDToTypeID( "Bl  " );

                    //desc9.putDouble( idBl, 17.062257 );   original line

                    desc9.putDouble( idBl, blueC );

                var idRGBC = charIDToTypeID( "RGBC" );

                desc8.putObject( idClr, idRGBC, desc9 );

                var idoverprint = stringIDToTypeID( "overprint" );

                desc8.putBoolean( idoverprint, false );

            var idFrFX = charIDToTypeID( "FrFX" );

            desc7.putObject( idFrFX, idFrFX, desc8 );

        var idLefx = charIDToTypeID( "Lefx" );

        desc6.putObject( idT, idLefx, desc7 );

    executeAction( idsetd, desc6, DialogModes.NO );

}

Votes

Translate

Translate

Report

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
Engaged ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

LATEST

Chuck Uebele,It was perfect now! Everything was solved with just the App.Refresh (), this could not be missing for that kind of adjustment! Thank you one more time!

Votes

Translate

Translate

Report

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