1 Reply Latest reply on Jun 26, 2013 10:38 AM by prpurcell

    Unicode name from layer


      Right now I am using the following method to get the name of my currently active layer


      SPErr GetLayerName(char* name, int length)


                SPErr error = 0;



                error = PIUGetInfo(classLayer, keyName, name, &length);

                if (error) goto onError;




           return error;



      Then I can use


      const int MAX_NAME = 256;

      char** names = new char*[layerCount];

      for (int i = 0; i < layerCount; ++i)



           names[i] = new char[MAX_NAME];

           GetLayerName(names[i], MAX_NAME);



      What I need to do is get a unicode string...as of right now I am developing

      the plugin on Windows, for the time being portability is not a concern (it will

      be, but I just want to get it funcitoning first) so I don't mind using wchar_t.


      I've tried looking for some kind of key i.e. keyUnicodeName, but can't find

      anything useful down that road.


      I saw another user of this forum using the following...


      auto &layerInfo = globals->exportParamBlock->documentInfo->layersDescriptor;

      for (int i = 0; i < layerN; ++i)


           std::u16string utfStr = layerInfo->unicodeName;

           layerInfo = layerInfo->next;



      but it seems that his was an export plugin, while mine is an automation...



      Any suggestions would be greatly appreciated



        • 1. Re: Unicode name from layer
          prpurcell Level 1

          Just in case anyone comes across this with the same problem...


          What I ended up doing was creating an export plugin based on the History plugin that is provided with the SDK.


          I tore pretty much everything out of that example and got the following...


          Here is what remains of History.h


          #ifndef _HISTORY_H_

          #define _HISTORY_H_



          #include "PIExport.h"

          #include "PIUtilities.h"

          #include "DialogUtilities.h"

          #include "HistoryTerminology.h"



          typedef struct Globals


                    short                              *result;

                    ExportRecord          *exportParamBlock;



          } Globals, *GPtr;



          #define gStuff (globals->exportParamBlock)



          #endif // _HISTORY_H_


          ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////


          and here is History.cpp


          #include "History.h"


          #include <string>

          #include <iostream>


          void InitGlobals(Ptr globalPtr);

          void ValidateParameters(GPtr globals);


          SPBasicSuite * sSPBasic = 0;


          DLLExport MACPASCAL void PluginMain(const int16 selector,

                                                                                                    ExportRecordPtr exportParamBlock,

                                                                                                    intptr_t *data,

                                                                                                    int16 *result)


                    sSPBasic = ((ExportRecordPtr)exportParamBlock)->sSPBasic;


                    GPtr globals = 0;

                    Ptr globalPtr = 0;


                    globalPtr = AllocateGlobals(result, exportParamBlock, exportParamBlock->handleProcs,

                                                                                          sizeof(Globals), data, InitGlobals);


                    if (!globalPtr)


                              *result = memFullErr;




                    globals = (GPtr)globalPtr;


                    auto& layerInfo = globals->exportParamBlock->documentInfo->layersDescriptor;

                    if (layerInfo->next)


                              int layerCount = globals->exportParamBlock->documentInfo->layerCount;





                                        std::u16string utfStr = layerInfo->unicodeName;

                                        layerInfo = layerInfo->next;


                         // Output utfStr to document however you'd like here




                    if ((Handle)*data) PIUnlockHandle((Handle)*data);




          void InitGlobals(Ptr globalPtr)

          { GPtr globals = (GPtr)globalPtr; }//InitGlobals


          ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////


          And in my automation plugin I have the following method


          SPErr ExecuteExternalPlugin()


                    SPErr error = 0;


                    PIActionDescriptor result = 0;

                    PIActionDescriptor desc00000138 = 0;


                    error = sPSActionDescriptor->Make(&desc00000138);

                    if (error) goto onError;


                    error = sPSActionDescriptor->PutClass(desc00000138, keyUsing, 'Test'); // Note**********

                    if (error) goto onError;


                    error = sPSActionControl->Play(&result, eventExport, desc00000138, plugInDialogSilent);

                    if (error) goto onError;



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

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

                    return error;



          When the external / hidden plugin is finished writing the needed info to a file,

          the automation plugin opens that file and does what it needs with it.


          Maybe not the prettiest solution but it works.




          Whatever is defined in your external / hidden plugin's pluginClassID in the

          external plugin's .r is the final integer argument to to the PutClass() call


          that integer gets represented as a multicharacter literal in this case 'Test'


          Hope this can help someone in the future