Skip navigation
Royt2011
Currently Being Moderated

How to know which channel is selected for the current document

Jul 18, 2012 3:39 AM

Tags: #select #classchannel #getter

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.

 
Replies
  • Currently Being Moderated
    Jul 18, 2012 4:20 AM   in reply to Royt2011

    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;

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points