11 Replies Latest reply on Aug 27, 2015 2:07 AM by LeoTaro

    Add new 'Export' Button in Title bar next to File, Edit,Object options.

    omar.92

      Hi Everyone,

       

      I want to create a new button in adobe illustrator CS6 on the main title bar which for now does the same functionality as 'Save as' button.

       

      I have been reading the reference documents provided with adobe illustrator cs6 sdk but can't find anything related to my current problem. Will really appreciate if anyone of you could tell me how to achieve this functionality ?

        • 1. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
          A. Patterson Level 4

          Sorry, just need some clarification: are you talking about a button on the toolbar or a menuitem on the File menu? Just not sure what you mean by 'title bar'.

          • 2. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
            omar.92 Level 1

            Sorry for using title bar yes I mean the toolbar.

             


            My first preference is having a button on the toolbar if that's not possible or more difficult to achieve then having a menuitem on the File menu can also work for me.

            • 3. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
              A. Patterson Level 4

              There's no API for adding third party buttons to the Illustrator toolbar (you can create your own though -- we do!). Adding a menuitem to the File Menu though is quite simple. When you create a menu, you have to specify a menu group. You can of course create your own, but you can also use pre-defined ones, which are listed in AIMenuGroups.h. We add one to the kOpenMenuGroup ourselves, but there are others (e.g. kSaveMenuGroup is probably the one you'd want to try first).

              • 4. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                omar.92 Level 1

                I have written the following code but it's not working. Can you help me identify the issue

                 

                #include "IllustratorSDK.h"

                #include "AIMenuGroups.h"

                 

                // Tell Xcode to export the following symbols

                #if defined(__GNUC__)

                #pragma GCC visibility push(default)

                #endif

                // Plug-in entry point

                extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message);

                // Tell Xcode to return to default visibility for symbols

                #if defined(__GNUC__)

                #pragma GCC visibility pop

                #endif

                 

                extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message)

                {

                  SPBasicSuite *mBasic = ((SPMessageData*)message)->basic;

                  AIMenuSuite *sAIMenu;

                  mBasic->AcquireSuite(kAIMenuSuite, kAIMenuVersion, (const void**)&sAIMenu);

                 

                  SPPluginRef plugin;

                  AIPlatformAddMenuItemDataUS menuData;

                  AIPlatformAddMenuItemDataUS pluginMenuData;

                 

                  const char *menuGroupCStr = "New XX Group";

                  const char *menuCStr = "XX's Menu...";

                  const char *pluginCStr = "XX Export";

                 

                  menuData.groupName = kSaveMenuGroup;

                  menuData.itemText = ai::UnicodeString(menuCStr);

                  pluginMenuData.groupName = menuGroupCStr;

                  pluginMenuData.itemText = ai::UnicodeString(pluginCStr);

                  const char *Key = NULL;

                  AIMenuItemOption options = kMenuItemIsSeparator;

                  AIMenuItemHandle menuItem = nil;

                 

                  AIErr error = sAIMenu->AddMenuItem(((SPInterfaceMessage*)message)->d.self, NULL, &menuData, 0, &menuItem);

                 

                 

                 

                  return error;

                 

                }

                • 5. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                  A. Patterson Level 4

                  On the face of it, no, I don't see anything wrong. Though it's worth noting that instead passing in NULL for the menu name, passing in a name will let the user apply a shortcut to it.

                   

                  What's the error code you get back? I assume it doesn't return kNoErr (0).

                  • 6. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                    A. Patterson Level 4

                    Wait, hold on, I thought of something. You maybe trying to add a menu too early. We don't add our menus until we respond to the kSPInterfaceCaller/kSPInterfaceStartupSelector combination. It's possible if you do it before then the required resources aren't available.

                    • 7. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                      A. Patterson Level 4

                      Also, if you're catching that combination, message is SPInterfaceMessage*, not SPMessageData*

                      • 8. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                        omar.92 Level 1

                        I don't get any build errors and I've modified the code by referencing kSPInterfaceCaller/kSPInterfaceStartupSelector combination. But still no effect. My plugin doesn't load

                        #include "IllustratorSDK.h"

                        #include "AIMenuGroups.h"

                         

                         

                         

                         

                        // Tell Xcode to export the following symbols

                        #if defined(__GNUC__)

                        #pragma GCC visibility push(default)

                        #endif

                        // Plug-in entry point

                        extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message);

                        // Tell Xcode to return to default visibility for symbols

                        #if defined(__GNUC__)

                        #pragma GCC visibility pop

                        #endif

                         

                         

                        extern "C"

                        {

                          AIUnicodeStringSuite* sAIUnicodeString = NULL;

                          SPBlocksSuite* sSPBlocks = NULL;

                        }

                         

                         

                         

                         

                        extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message)

                        {

                         

                          

                          SPBasicSuite *mBasic = ((SPMessageData*)message)->basic;

                          AIMenuSuite *sAIMenu;

                          ASErr error = kNoErr;

                         

                         

                          if (mBasic->IsEqual(caller, kSPInterfaceCaller))

                          {

                          AIUserSuite *sAIuser = nil;

                         

                         

                          error = mBasic->AcquireSuite(kAIUserSuite,

                          kAIUserSuiteVersion, (const void**)&sAIuser);

                          error = mBasic->AcquireSuite(kAIUnicodeStringSuite,

                          kAIUnicodeStringVersion, (const void**)&sAIUnicodeString);

                          error = mBasic->AcquireSuite(kSPBlocksSuite,

                          kSPBlocksSuiteVersion, (const void**)&sSPBlocks);

                         

                         

                          mBasic->AcquireSuite(kAIMenuSuite, kAIMenuVersion, (const void**)&sAIMenu);

                         

                         

                          if (mBasic->IsEqual(selector, kSPInterfaceStartupSelector))

                          {

                          sAIuser->MessageAlert(ai::UnicodeString("Hello World!"));

                          SPPluginRef plugin;

                          AIPlatformAddMenuItemDataUS menuData;

                          AIPlatformAddMenuItemDataUS pluginMenuData;

                         

                         

                          const char *menuGroupCStr = "New XX Group";

                          const char *menuCStr = "XX's Menu...";

                          const char *pluginCStr = "XX Export";

                         

                         

                          menuData.groupName = kSaveMenuGroup;

                          menuData.itemText = ai::UnicodeString(menuCStr);

                          pluginMenuData.groupName = menuGroupCStr;

                          pluginMenuData.itemText = ai::UnicodeString(pluginCStr);

                          const char *Key = NULL;

                          AIMenuItemOption options = kMenuItemIsSeparator;

                          AIMenuItemHandle menuItem = nil;

                          AIErr error1 = sAIMenu->AddMenuItem(((SPInterfaceMessage*)message)->d.self, NULL, &menuData, 0, &menuItem);

                          }

                         

                         

                          //AIErr error1 = sAIMenu->AddMenuItem(((SPInterfaceMessage*)message)->d.self, NULL, &menuData, 0, &menuItem);

                          /*if (!error) {

                          *menuItemHandle = menuItem;

                          }*/

                          }

                          return error;

                         

                        }



                        • 9. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                          A. Patterson Level 4

                          The plugin not loading may not be related to your code

                           

                          If you put a breakpoint on the first line, do you hit it? If not, there's something wrong with the way you're building the plugin. There should be a sample skeleton plugin with project in the SDK. It's frankly much easier to just take that skeleton and add your code to it -- it comes with nice stubs for things like 'AddMenus'.

                          • 10. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                            LeoTaro Level 4

                            Most common reasons for plugins not loading are trying to load a 32 bit plugin in a 64 bit version of Illustrator or trying to load into an older version of Illustrator than the SDK the plugin was built with. See the other threads about plugins not loading.

                            • 11. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                              omar.92 Level 1

                              I have already verified the plugin being of 64 bit (compatible with my system) and both SDK and AI is CS6 version.

                               

                              I have created another test example plugin which loads fine and works great but this plugin of adding new menuitem on the File menu doesn't even load :/ !!

                              • 12. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                                omar.92 Level 1

                                A. Patterson can you kindly tell me which sample project you are talking about or it'll be a great help if you could post the skeleton code here !!

                                • 13. Re: Add new 'Export' Button in Title bar next to File, Edit,Object options.
                                  LeoTaro Level 4

                                  If your plugin is returning a non zero value when it gets the kSPAccessCaller kSPAccessReloadSelector it will fail to load. There is example code for adding menu items in the samplecode/common/source directory (SDKAboutPluginsHelper.cpp). This is the SDKAboutPluginsHelper::AddAboutPluginsMenuItem function from the CS6 SDK:

                                   

                                  AIErr SDKAboutPluginsHelper::AddAboutPluginsMenuItem(SPInterfaceMessage* message,

                                    const char* companyMenuGroupName,

                                    const ai::UnicodeString& companyName,

                                    const char* pluginName,

                                    AIMenuItemHandle* menuItemHandle)

                                  {

                                    AIErr error = kNoErr;

                                   

                                   

                                    if (fAIMenu == nil) {

                                    error = message->d.basic->AcquireSuite( kAIMenuSuite, kAIMenuSuiteVersion, (const void **) &fAIMenu );

                                    }

                                   

                                    if (!error && fAIMenu != nil) {

                                    // Add an about plug-ins menu group for the given company under Illustrator's about group.

                                    bool exists = false;

                                    error = this->GroupExists(companyMenuGroupName, exists);

                                    if (!error && !exists) {

                                    AIPlatformAddMenuItemDataUS companyRootMenuData;

                                    companyRootMenuData.groupName = kAboutMenuGroup;

                                    companyRootMenuData.itemText = companyName;

                                    AIMenuItemHandle companyRootMenuItemHandle = nil;

                                    error = fAIMenu->AddMenuItem(message->d.self, NULL, &companyRootMenuData, kMenuItemNoOptions, &companyRootMenuItemHandle);

                                    if (!error) {

                                    AIMenuGroup companyRootMenuGroup = nil;

                                    error = fAIMenu->AddMenuGroupAsSubMenu(companyMenuGroupName, kMenuGroupSortedAlphabeticallyOption, companyRootMenuItemHandle, &companyRootMenuGroup);

                                    }

                                    }

                                    }

                                   

                                    if (!error && fAIMenu != nil) {

                                    // Add menu item for this plug-in under the company's about plug-ins menu group.

                                    AIPlatformAddMenuItemDataUS aboutPluginMenuData;

                                    aboutPluginMenuData.groupName = companyMenuGroupName;

                                    aboutPluginMenuData.itemText = ai::UnicodeString(pluginName);

                                    AIMenuItemHandle aboutPluginMenuItemHandle = nil;

                                    error = fAIMenu->AddMenuItem(message->d.self, NULL, &aboutPluginMenuData, kMenuItemNoOptions, &aboutPluginMenuItemHandle);

                                    if (!error) {

                                    *menuItemHandle = aboutPluginMenuItemHandle;

                                    }

                                    }

                                   

                                   

                                    if (fAIMenu != nil) {

                                    message->d.basic->ReleaseSuite( kAIMenuSuite, kAIMenuSuiteVersion );

                                    fAIMenu = nil;

                                    }

                                   

                                   

                                    return error;

                                  }