2 Replies Latest reply: Jul 19, 2012 12:19 AM by Royt2011 RSS

    How to know which channel is selected for the current document

    Royt2011 Community Member

      In photoshop, open a CMYK file, by default the 4 channels are all selected. Now I just select one or two of them, In my plug-in code, how to know which channel is selected?

       

      "Get Info Functions" chapter of "Automation Tutorial" introduces a getter function to get information from Photoshop, for "classChannel", there are 4 available keys: keyChannelName, keyItemIndex, keyCount, keyVisible, but none of them indicates if the channel is selected.

       

      Now that we can play an event of selecting channel in photoshop, so I think there should be a way to get the selection status of the channels. Could any one give me some advice? Thanks very much.

        • 1. Re: How to know which channel is selected for the current document
          MOMIR ZECEVIC Community Member

          Every channel that is selected will have keyVisible true.

           

          Trouble is if you want to see which is selected from visible ones. I dont know for channels but it works for a layers so i suppose that it will work there too.

           

          When you perform action or get property on a layer if you use "enumTarget"  for adressing are done using currently active or selected or as implied by name  default targer layer.

          Now. if you want to know what is a current channel just get its name.

           

           

          Here is an example how to hide current  layer and any layer  using index.

          Unfortunately i have no time at the moment to writte exact cod that you need, but if this do not help post here and i will try to do when i can.

           

          N

          Hope this helps.

          Momir Zecevic

           

           

          Example

           

          //

          // HideCurrentLayer

          //

          SPErr AMAutoPlugin::HideCurrentLayer(void)

          {

                  SPErr error = kSPNoError;

                  PIActionDescriptor result = NULL;

                  PIActionDescriptor tempDescriptor = NULL;

                  PIActionList tempList = NULL;

                  PIActionReference tempReference = NULL;

           

                  error = sPSActionDescriptor->Make(&tempDescriptor);

                  if (error) goto returnError;

           

                  error = sPSActionList->Make(&tempList);

                  if (error) goto returnError;

           

                  error = sPSActionReference->Make(&tempReference);

                  if (error) goto returnError;

           

                  error = sPSActionReference->PutEnumerated(tempReference, classLayer, typeOrdinal, enumTarget); //enumTarget - currently

                  if (error) goto returnError;                                                                                                                         //active -selected

           

                  error = sPSActionList->PutReference(tempList, tempReference);

                  if (error) goto returnError;

           

                  error = sPSActionDescriptor->PutList(tempDescriptor, keyNull, tempList);

                  if (error) goto returnError;

           

                  error = sPSActionControl->Play(&result, eventHide, tempDescriptor, plugInDialogSilent);

                  if (error) goto returnError;

           

          returnError:

                  if (result != NULL) sPSActionDescriptor->Free(result);

                  if (tempDescriptor != NULL) sPSActionDescriptor->Free(tempDescriptor);

                  if (tempList != NULL) sPSActionList->Free(tempList);

                  if (tempReference != NULL) sPSActionReference->Free(tempReference);

                  return error;

          }

           

          }

           

          //

          // HideLayerByIndex

          //

          SPErr AMAutoPlugin::HideLayerByIndex(int32 index)

          {

                  SPErr error = kSPNoError;

                  PIActionDescriptor result = NULL;

                  PIActionDescriptor tempDescriptor = NULL;

                  PIActionReference tempReference = NULL;

                  PIActionList tempList = NULL;

             

                  error = sPSActionDescriptor->Make(&tempDescriptor);

                  if (error) goto returnError;

                             

                  error = sPSActionList->Make(&tempList);

                  if (error) goto returnError;

           

                  error = sPSActionReference->Make(&tempReference);

                  if (error) goto returnError;

           

                  error = sPSActionReference->PutIndex(tempReference, classLayer, index);

                  if (error) goto returnError;

           

                  error = sPSActionList->PutReference(tempList, tempReference);

                  if (error) goto returnError;

           

                  error = sPSActionDescriptor->PutList(tempDescriptor, keyNull, tempList);

                  if (error) goto returnError;

           

                  error = sPSActionControl->Play(&result, eventHide, tempDescriptor, plugInDialogSilent);

                  if (error) goto returnError;

           

          returnError:

                  if (result != NULL) sPSActionDescriptor->Free(result);

                  if (tempDescriptor != NULL) sPSActionDescriptor->Free(tempDescriptor);

                  if (tempList != NULL) sPSActionList->Free(tempList);

                  if (tempReference != NULL) sPSActionReference->Free(tempReference);

                  return error;

          }

          • 2. Re: How to know which channel is selected for the current document
            Royt2011 Community Member

            Thank you.

             

            The 'enumTarget' means currently selected things (layer, channel, etc.), so I tried the code below. And then I could get the seleted channel's index through keyword 'keyItemIndex'. If there are multi channels selected the 'Get' method won't be executed successfully.

             

            I just write similar code applying to layers, if mult layers selected, the 'Get' method can run successfuly, but only one value(a selected layer's index) can be fetched. Is there any other keyword corresponding to a list or array that contains all selected indexes?

             

             

            SPErr NestD::GetSelectedChannels(int32 *channelIndex)

            {

            PIActionReference ref = NULL;

            PIActionDescriptor result = NULL;

            SPErr error = kSPNoError;

            Boolean hasKey;

             

            error = sPSActionReference->Make(&ref);

            if (error) goto returnError;

             

            error = sPSActionReference->PutProperty(ref, classProperty, keyItemIndex);

            if (error) goto returnError;

             

            error = sPSActionReference->PutEnumerated(ref, classChannel, typeOrdinal, enumTarget);

            if (error) goto returnError;

             

            error = sPSActionControl->Get(&result, ref);

            if (error) goto returnError;

             

            error = sPSActionDescriptor->HasKey(result, keyItemIndex, &hasKey);

            if (error || !hasKey) goto returnError;

             

            error = sPSActionDescriptor->GetInteger(result, keyItemIndex, channelIndex);

            if (error) goto returnError;

             

            returnError:

            if (result) sPSActionDescriptor->Free(result);

            if (ref) sPSActionReference->Free(ref);

             

            return error;

            }