11 Replies Latest reply on Apr 1, 2011 8:47 AM by Jeremy Knudsen

    Is there any way to get a Photoshop panel to receive real-time color updates?

    pixelG Level 1

      Hello CS SDK Community!

       

      I am hoping I can tap into your expert knowledge here as I am by no means an expert (still intellectually curious and always wanting to learn). I've been able to successfully build a couple panels and write some useful scripts for Photoshop. But up until now, I wouldn't say I have done anything overly ambitious. Now, I am ready take that next step.

       

      I am now developing a Photoshop panel that does some calculations and analysis between foreground and background colors. But I need to figure out a way for my panel to receive real-time updates of foreground and background colors, but I honestly don't know how or where to start. More specifically, I would like my panel to receive these kinds of events so that I can update the associated color value from Photoshop:

       

      1. Foreground and background color change events to keep in sync with Photoshop's foreground and background colors:
        fgbgColors.png
      2. Events associated with Photoshop's color picker dialog and how the panel can get the "new color" value (before the user clicks OK):
        colorPicker.png
      3. The color that is under the mouse cursor (real-time color data as can be seen in the INFO pane):
        infoPane.png

       

      Thank you in advance for any help you might be able to provide!

      Jeremy

        • 1. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
          zak.nelson Level 3

          I'd start by using the ScriptListener plugin to see if Photoshop fires the events you're interested in (my hunch is that your last two events are not available). This page: http://cssdk.host.adobe.com/sdk/1.0/docs/WebHelp/app_notes/photoshop.htm has a decent step-by-step on how to listen for events using the CS SDK in Photoshop.

           

          Zak

          1 person found this helpful
          • 2. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
            pixelG Level 1

            Thanks Zak. Much appreciated. That's a good first step that I didn't think of to try... I'll report back and let the forum know if anything useful comes out of it.

            • 3. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
              pixelG Level 1

              Here is sample output I received when specifying a new foreground color using the HSB color space (the output will be different depending on which color space you have selected in the dialog at the time of committing to the new color and clicking "OK"):

               

               

              HSB color space (via Color Picker dialog):

              HSB.png
              // HSB Color Picker Output =======================================================
              var idsetd = charIDToTypeID( "setd" );
                  var desc3 = new ActionDescriptor();
                  var idnull = charIDToTypeID( "null" );
                      var ref2 = new ActionReference();
                      var idClr = charIDToTypeID( "Clr " );
                      var idFrgC = charIDToTypeID( "FrgC" );
                      ref2.putProperty( idClr, idFrgC );
                  desc3.putReference( idnull, ref2 );
                  var idT = charIDToTypeID( "T   " );
                      var desc4 = new ActionDescriptor();
                      var idH = charIDToTypeID( "H   " );
                      var idAng = charIDToTypeID( "#Ang" );
                      desc4.putUnitDouble( idH, idAng, 231.525879 );
                      var idStrt = charIDToTypeID( "Strt" );
                      desc4.putDouble( idStrt, 100.000000 );
                      var idBrgh = charIDToTypeID( "Brgh" );
                      desc4.putDouble( idBrgh, 47.367056 );
                  var idHSBC = charIDToTypeID( "HSBC" );
                  desc3.putObject( idT, idHSBC, desc4 );
              executeAction( idsetd, desc3, DialogModes.NO );

              =


              So that is a hopeful first step. I understand that I can use this code (or modify it to turn it into a function) in order to set the foreground color of Photoshop from my script. But I don't know how to "listen" for this event so that when it is triggered I could tell my panel to update itself with the user specifies a new color via the Color Picker.

               

              Any ideas or next steps for me to try?

               

              Thanks again for all your help!

              Jeremy

              • 4. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                zak.nelson Level 3

                You should find that there is a 4-character code that is associated with the overall action, in this case that 4-character code is "setd". I think in general the first id is the one you'll want to listen for. Refer back to http://cssdk.host.adobe.com/sdk/1.0/docs/WebHelp/app_notes/photoshop.htm to see how to use that 4 character code to listen for the desired event. Note that the approach using the PSEventAdapter will only apply if you have CS Extension Builder.

                 

                One thing to look out for is that "setd" may be fired in other scenarios as well. If it is, then just make sure the color has indeed changed before you call your code.

                1 person found this helpful
                • 5. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                  pixelG Level 1

                  Hi Zac,

                   

                  Thanks for your help thus far. I followed the instructions but I am receiving a 1093 Syntax Error (Type: "Flex problem") when declaring the following private contstant in the MXML file (shown below in magenta):

                   

                   

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <mx:Application

                   

                  xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="0xD6D6D6" backgroundGradientColors="[0xD6D6D6,0xD6D6D6]" layout="absolute" creationComplete="init()" xmlns:csxslogtargets="com.adobe.csxs.logging.targets.*" width="304" height="326">

                   

                   

                  <mx:Script>

                  <![CDATA[

                   

                       import com.adobe.csawlib.photoshop.Photoshop;

                   

                       import com.adobe.photoshop.*;

                   

                       import com.adobe.csxs.core.CSXSInterface;

                   

                       import mx.collections.ArrayCollection;

                   

                       import mx.logging.*;

                   

                       private const SETD_INT:int = Photoshop.app.charIDToTypeID(’setd’);

                   

                   

                       private function myPhotoshopCallback(eventID:Number, descID:Number):void {

                   

                            var desc:ActionDescriptor = new ActionDescriptor();

                            desc.fromID(descID);

                   

                            switch (eventID)

                            {

                   

                                 case SETD_INT:

                   

                                      //handle setd case

                   

                                      //note: will need to check if foreground or background color changed from its old value

                   

                                      break;

                   

                                 default:

                   

                                      //should not get here

                   

                                      break;

                            }

                       }

                   

                   

                       public function init():void{

                            CSXSInterface.instance.evalScript(

                  "PhotoshopPersistent");

                   

                   

                      

                            //register for Photoshop events

                            CSXSInterface.instance.evalScript(

                  "PhotoshopRegisterEvent", SETD_INT);

                            ExternalInterface.addCallback(

                  "PhotoshopCallback" + CSXSInterface.getInstance().getExtensionId(), myPhotoshopCallback);

                       }

                   

                  .

                  .

                  .

                   

                       ]]>

                   

                   

                  </mx:Script>

                  Do you know where this is supposed to go or if this is the correct placement, what might be wrong?

                  </mx:Script>

                   

                  Do you know where this is supposed to go or if this is the correct placement, what might be wrong?

                  Do you know where this is supposed to go or if this is the correct placement, what might be wrong?

                  • 6. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                    zak.nelson Level 3

                    What you have looks like valid syntax.

                     

                    My guess is that in copying the code from the documentation, you copied smart quotes (http://en.wikipedia.org/wiki/Quotation_mark_glyphs) and the compiler won't like that. I would manually replace all quotes and retype them to verify that they're all dumb quotes.

                    • 7. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                      pixelG Level 1

                      Zak! Thank you thank you thank you SO MUCH! You guided me step-by-step right to the solution. Things are working now, but for the benefit of others, I wanted to follow up with one little tweak I needed to make to the above code before things started working correctly for me.

                       

                      When I tested and debugged the above code, Photoshop would not respond to the 'setd' event that I had registered. For example, when I changed the foreground color in Photoshop (a 'setd' event), the myPhotoshopCallback function was never called and the code in the case statement would not execute.

                       

                      I was a bit perplexed why this was happening, since SETD_INT was registering correctly with the follwing value: SETD_INT = 1936028772 [0x73657464]


                      Then I saw the error of my ways in the Console:

                       

                      11/12/2010 10:07:24.105 [DEBUG] com.adobe.csxs.core.CSXSInterface getInstance()

                      11/12/2010 10:07:24.105 [DEBUG] com.adobe.csxs.external.CommunicationUtils [DispatchingRequest functionName="PhotoshopRegisterEvent" params="1936028772"]

                      11/12/2010 10:07:24.106 [ERROR] com.adobe.csxs.external.CommunicationUtils [The array while dispatching request should contain only strings arrParams="Version 2.0,com.color,1936028772"]

                       

                      Because I was only registering for one event (instead of three events as in the example), I was missing the fact that the parameter needed to be a string (not an integer). When I removed the other event mames from the parameter list I had also removed the + "," which when present converted the values into a string. I simply added +"" after the single SETD_INT parameter and everything works now. Here is the change I needed to make.

                       

                       

                      //register for these Photoshop events

                      CSXSInterface.instance.evalScript("PhotoshopRegisterEvent", SETD_INT + "");

                       

                      So I wanted to thank you again! You are very much appreciated! This has opened the door to many new possibilities for me in my development of custom panels!

                       

                      Have a great weekend my friend,

                      Jeremy

                      • 8. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                        Mark Erickson Level 1

                        Nice catch, the automatic conversions can be tricky.

                         

                        Suggestion: Rather than using the implicit conversion using + with an empty string, generally better to use the .toString() function. This makes it obvious what is needed.

                        • 9. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                          pixelG Level 1

                          I was thinking about using toString() ... this was just a quick and dirty test to see if that was the issue. Thank you all for your help!!!

                          • 10. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                            DBarranca Level 4

                            PixelG,

                            have you been able to retrieve the color/position under the mouse cursor?

                            I'm working on a project where I'd like to implement some kind of data gathering: scripting ColorSamplers is giving me good results, nevertheless I'd better need more real time interaction.

                            Any suggestion is really appreciated!

                             

                            Davide

                            • 11. Re: Is there any way to get a Photoshop panel to receive real-time color updates?
                              Jeremy Knudsen Level 1

                              Hey there this is PixelG a.k.a. Jeremy Knudsen (I don't know how to consolodiate these two accounts )--

                               

                              There is not a straightforward way that I am aware of and I have sought the counsel of those who work for Adobe who would know. It would be a GREAT addition to CS6!!!

                               

                              If you could get at the cursor position within the document you could cobble up a non-realtime workaround by setting the position of a ColorSampler to equal the cursor position and then reading its color property. This, of course, sounds neither possible nor desirable.