9 Replies Latest reply on Jan 2, 2014 6:43 AM by TomT-shirts

    Select/Change Certain Color




      I have been scripting in various Adobe products for a while but I am simply stumped on this one.


      I have a series of PNG files that consist of various shapes. The shapes are solid black and the rest of the document is transparent.


      I wrote a script to pull all the documents into one new Photoshop file and place each file/shape on its own new layer.


      I then randomize the order of the layers. This in theory generates kind of a unique "pattern".


      What I want to do now is change the black pixels of each layer to a different color.


      For example, all the black pixels in layer 1 will be changed to red. All the black pixels in layer 2 will be changed to green, etc, etc.


      Since the black PNG shapes are randomly placed in different layers, this will again give a very unique and colorful pattern.


      I am good up to this point. However, I cannot figure out how to change the black pixels to a specific color using the scripting interface.


      I thought of selecting only the black pixels and then filling with a color. Couldn't figure out how to do that. Thought of applying a color shifting script. Couldn't figure out how to do that. I even thought of apply a style or filter. Couldn't figure out how to do that either.


      Any help or suggestions or examples would be greatly appreciated.


      Thank you!

        • 1. Re: Select/Change Certain Color
          MCLMasterKey Level 1

          Shortly after I posted this I thought I had a stroke of genius.


          I used:

          transparentPixelsLocked = true;




          This worked (sort of).


          Now, when I issue the selection.fill(); command it pops open the Fill dialog box.


          If I set transparentPixelsLocked = false; the Fill dialog box is not displayed when issuing the selection.fill(); command. Very odd.


          I tried setting app.displayDialogs = DialogModes.NO; but that then generates an error.


          Any thoughts?



          • 2. Re: Select/Change Certain Color
            c.pfaffenbichler Level 9

            Have you tried using the ScriptingListener code for something like the Layer Style Color Overlay for example?

            • 3. Re: Select/Change Certain Color
              MCLMasterKey Level 1

              No I have not. I am not familiar wtih the "ScriptingListener".


              Could you point me to a tutorial on that?


              I would still love to know why the Fill dialog box appears and if/how I can supress it -- if anyone has any ideas?



              • 4. Re: Select/Change Certain Color
                MCLMasterKey Level 1

                I found the Scripting Listener plugin and documentation on Adobe's site.




                Installed it and followed the instructions.


                It works!


                I have to clean up my code and do some more automation, but the layer is now being changed using the Color Overlay via Scripting Listener.


                Thanks for the push in the right direction.

                1 person found this helpful
                • 5. Re: Select/Change Certain Color
                  c.pfaffenbichler Level 9

                  It might be usefull to wrap the code in a function that takes the color values you want as arguments so that one function can be used for Color Overlays of any color.

                  • 6. Re: Select/Change Certain Color
                    MCLMasterKey Level 1

                    Yes, the Scripting Listener ZIP file came with some documentation on how to wrap it in a function and pass in your own values for certain variables.


                    I have one function and a loop that calls it for each layer and overlays a different color for each layer.


                    Works like a charm.


                    Thanks again for all your help!

                    • 7. Re: Select/Change Certain Color
                      TomT-shirts Level 1

                      Can you please post your code for your function? I was very happy to find this thread because I'm up against something similar; I need to find the color of the existing color overlays on layers with a script. While you found a solution with help from the forum, it doesn't help others unless you post it!


                      I'd really appreciate seeing it,





                      • 8. Re: Select/Change Certain Color
                        MCLMasterKey Level 1



                        1) Based on your description/question, my script does not do what you are trying to do. Mine "applies" color. It does not "find" the color.


                        2) Below is my function for applying a color overlay



                        function applyColorOverlay(intRed, intGreen, intBlue) {
                            var idsetd = charIDToTypeID( "setd" );
                            var desc5 = new ActionDescriptor();
                            var idnull = charIDToTypeID( "null" );
                                var ref3 = new ActionReference();
                                var idPrpr = charIDToTypeID( "Prpr" );
                                var idLefx = charIDToTypeID( "Lefx" );
                                ref3.putProperty( idPrpr, idLefx );
                                var idLyr = charIDToTypeID( "Lyr " );
                                var idOrdn = charIDToTypeID( "Ordn" );
                                var idTrgt = charIDToTypeID( "Trgt" );
                                ref3.putEnumerated( idLyr, idOrdn, idTrgt );
                            desc5.putReference( idnull, ref3 );
                            var idT = charIDToTypeID( "T   " );
                                var desc6 = new ActionDescriptor();
                                var idScl = charIDToTypeID( "Scl " );
                                var idPrc = charIDToTypeID( "#Prc" );
                                desc6.putUnitDouble( idScl, idPrc, 100.000000 );
                                var idSoFi = charIDToTypeID( "SoFi" );
                                    var desc7 = new ActionDescriptor();
                                    var idenab = charIDToTypeID( "enab" );
                                    desc7.putBoolean( idenab, true );
                                    var idMd = charIDToTypeID( "Md  " );
                                    var idBlnM = charIDToTypeID( "BlnM" );
                                    var idNrml = charIDToTypeID( "Nrml" );
                                    desc7.putEnumerated( idMd, idBlnM, idNrml );
                                    var idOpct = charIDToTypeID( "Opct" );
                                    var idPrc = charIDToTypeID( "#Prc" );
                                    desc7.putUnitDouble( idOpct, idPrc, 100.000000 );
                                    var idClr = charIDToTypeID( "Clr " );
                                        var desc8 = new ActionDescriptor();
                                        var idRd = charIDToTypeID( "Rd  " );
                                        desc8.putDouble( idRd, intRed );
                                        var idGrn = charIDToTypeID( "Grn " );
                                        desc8.putDouble( idGrn, intGreen );
                                        var idBl = charIDToTypeID( "Bl  " );
                                        desc8.putDouble( idBl, intBlue );
                                    var idRGBC = charIDToTypeID( "RGBC" );
                                    desc7.putObject( idClr, idRGBC, desc8 );
                                var idSoFi = charIDToTypeID( "SoFi" );
                                desc6.putObject( idSoFi, idSoFi, desc7 );
                            var idLefx = charIDToTypeID( "Lefx" );
                            desc5.putObject( idT, idLefx, desc6 );
                            executeAction( idsetd, desc5, DialogModes.NO );


                        3) It doesn't really help your cause to tell people they are not being helpful by not doing what you want them to do.


                        4) To continue with #3, I did indeed post the solution to the problem. Acutally,  c.pfaffenbichler posted the solution as indicated by the CORRECT tag. I confirmed his solution was correct for my issue and marked it as CORRECT and then went on to post a link and explain how I used the ScriptingListener code.


                        I hope this helps in some way.


                        Good luck!

                        • 9. Re: Select/Change Certain Color
                          TomT-shirts Level 1

                          Thank you, this is helpful.


                          - Tom.


                          On Dec 26, 2013, at 8:40 PM, MCLMasterKey <forums_noreply@adobe.com<mailto:forums_noreply@adobe.com