Advertisement
Guest User

Photoshop C++ Get Current Tool

a guest
Jan 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Doesn't work for versions before CS3
  3. static SPErr GetCurrentTool()
  4. {
  5.     SPErr err = 0;
  6.     PIActionReference toolPropRef = 0;
  7.     PIActionDescriptor inputDesc = 0;
  8.     if ((err = sPSActionReference->Make(&toolPropRef)))
  9.     {
  10.         debugOutError("sPSActionReference->Make() returned %d", err);
  11.         return err;
  12.     }
  13.     if ((err = sPSActionReference->PutProperty(toolPropRef, 'Prpr', 'Tool')))
  14.     {
  15.         debugOutError("sPSActionReference->PutProperty() returned %d", err);
  16.         goto end;
  17.     }
  18.     if ((err = sPSActionReference->PutEnumerated(toolPropRef, 'capp', 'Ordn', 'Trgt')))
  19.     {
  20.         debugOutError("sPSActionReference->PutEnumerated() returned %d", err);
  21.         goto end;
  22.     }  
  23.     if ((err = sPSActionControl->Get(&inputDesc, toolPropRef)))
  24.     {
  25.         debugOutError("sPSActionControl->Get() returned %d %s", err, PIUIDToChar(err));
  26.         goto end;
  27.     }          
  28.     unsigned int descCount = 0;
  29.     if ((err = sPSActionDescriptor->GetCount(inputDesc, &descCount)))
  30.     {
  31.         debugOutError("sPSActionDescriptor->GetCount() returned %d", err);
  32.         goto end;
  33.     }
  34.    
  35.     for (unsigned int c = 0; c < descCount; ++c)
  36.     {
  37.         // get the key for this item
  38.         DescriptorKeyID thisKeyID;
  39.         if ((err = sPSActionDescriptor->GetKey(inputDesc, c, &thisKeyID)))
  40.         {
  41.             debugOutError("sPSActionDescriptor->GetKey() returned %d", err);
  42.             goto end;
  43.         }
  44.  
  45.         // get the type for this key
  46.         DescriptorTypeID typeID;
  47.         if ((err = sPSActionDescriptor->GetType(inputDesc, thisKeyID, &typeID)))
  48.         {
  49.             debugOutError("sPSActionDescriptor->GetType() returned %d", err);
  50.             goto end;
  51.         }
  52.  
  53.         // we're looking for the enum
  54.         if (typeID != typeEnumerated)
  55.             continue;
  56.  
  57.         DescriptorEnumTypeID type;
  58.         DescriptorEnumID value;
  59.         sPSActionDescriptor->GetEnumerated(inputDesc, thisKeyID, &type, &value);
  60.         //debugOut("type: %d %s, value: %d %s", type, PIUIDToChar(type), value, PIUIDToChar(value));
  61.        
  62.         char classStr[255] = { 0 };
  63.         if ((err = sPSActionControl->TypeIDToStringID(type, classStr, 255)))
  64.         {
  65.             debugOutError("sPSActionControl->TypeIDToStringID() returned %d", err);
  66.             goto end;
  67.             }
  68.         setPSTool(classStr);
  69.     }
  70. end:
  71.     if (inputDesc)
  72.         sPSActionDescriptor->Free(inputDesc);
  73.     if (toolPropRef)
  74.         sPSActionReference->Free(toolPropRef);
  75.     return err;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement