Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Running plugin continuously in the background

Community Beginner ,
Jan 13, 2014 Jan 13, 2014

Hello, I'm just starting out trying to make a plugin for Illustrator CC and have been a bit stuck the past few days, so I have a few questions.  The plugin I'm trying to make would have it where when you mouse over a path, an annotation pops up to display the length of the path, reguardless of what tool you have selected. 

The major question I have is if it is possible to make a plugin that runs in the background without having to select it as a tool?

I've been going over the SDK and guides and have tried altering the annotator sample project along with trying to make it from scratch, but I haven't gotten the results I want.  I got Annotator to display the length of paths, but I can't remove it's tool properties or make it run like it's always selected.  When I've been tryng to build from scratch, I don't see how to track the cursor since it seems to need the AIToolSuite.  I've also tried to use AINotifierSuite with kAIArtSelectionChangedNotifier, but haven't gotten it to work correctly and it wouldn't work just by mousing over paths if I had.

Anyway, I was wondering if you guys would be able to point me in the right direction on making this because it seems like it shouldn't be nearly as difficult as it has been for me.

Details:

OSX 10.9.1

XCode 5.0.2

Illustrator CC 17.0.0

TOPICS
SDK
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 16, 2014 Jan 16, 2014

If you can get away with requiring a tool to be active, that's way, way easier. But we've been doing the OS-level trick for about 5 years now and it works, it just takes a lot more effort. I'd have to look into the Mac-side to see what it uses, I deal with the PC mostly.

Translate
Adobe
Enthusiast ,
Jan 14, 2014 Jan 14, 2014

You have to read carefully the sdk documentation (programmers guide). Illustrator plugin system is described.

What is a plugin, types of plugins, how it works, how it is loaed, ...... You will learn many, many things.

A plugin could be loaded during Illustrator startup and only unloaded at Illustrator shutdown. This plugin could do his "magic" during all that session. And It does not have to be a tool. 

Notifiers:

Plugin must register for the notifiers in which it is interested. The Notifier Suite is used to register and remove notification requests. (See AINotifierSuite).

Here it is a sample how it sould be implemented in your plugin.

myPlugin.h:

//Methods to be implemented.

ASErr StartupPlugin(SPInterfaceMessage* message);

ASErr AddNotifiers(SPInterfaceMessage* message);

ASErr Notify(AINotifierMessage* message);

myPlugin.cpp:


1- During startup, you have to register to notifications. (AddNotifiers).

/*

*/

ASErr

myPlugin::StartupPlugin(SPInterfaceMessage *message)

{

      ASErr error = Plugin::StartupPlugin( message );

      if (error) { return error; }

      error = AddNotifiers(message);

      if (error) { return error; }

     return error;

     // If StartupPlugin returns an error instead of kNoErr, Illustrator

     // will try to load this plug-in again later.

}

2- subscribe to notifiers.  kAICSXSPlugPlugSetupCompleteNotifier in this sample.

ASErr

myPlugin::AddNotifiers(SPInterfaceMessage* message)

{

          ASErr error = kNoErr;

 

     error = sAINotifier->AddNotifier(message->d.self, "myPlugin" kAICSXSPlugPlugSetupCompleteNotifier,

                             kAICSXSPlugPlugSetupCompleteNotifier, &fCSXSPlugPlugSetupCompleteNotifier);

              if (error) { return error; }

     return error;

}

3- handler (when the notification has been raised).

/*

*/

ASErr

myPlugin::Notify(AINotifierMessage* message)

{

          ASErr error = kNoErr;

 

               if ( message->notifier == fCSXSPlugPlugSetupCompleteNotifier )

               {

            //Do the magic here..........    

               } 

  

     return error;

}

I hope this will help.

Thomas.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2014 Jan 14, 2014

The definitely helps, thanks you!  It does raise another question from me though.  With CSXS, in the programmers guide, they give an example for adding event listeners where they listen for the event "Okclicked" and say that a list of possible events can be found at com.adobe.csxs.events, but when I go to the CSXSLibrary API Documentation online,

I'm not seeing events to listen for.  Is there somewhere like with ActionScript where a list of events that can be listed for are available or do I need to define the events myself?  Like if I was in flash listening for when the mouse went over an object, I would use MouseEvent.MOUSE_OVER, and I would think something similar should be possible with CSXS, but I'm not seeing how to get to this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 14, 2014 Jan 14, 2014

CSXS events are used to make flash-based extension and c++ plugin share datas.

Important: There are not notifiers!!!!

 

Your c++ plugin can subscribe to csxs events raised by your extension.

In the same way your extension can subscribe to csxs events raised by ypur plugin.

Give a look to programmers guide, in communication between plug-ins and extesnions section.

All is detailed.

In both cases (flex, c++), you have to register event listeners and implement event handlers.

If you need some samples, let me know!

You will have to find a name for each event you will create.

ex: com.toto.extension.event_raised.

Thomas.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 15, 2014 Jan 15, 2014

Alright, I've been working on trying to make the extension and plugin hybrid the past couple days, but I have some more questions.

My biggest problem at the moment is how to track the cursor's position without making a plugin tool. 

Is there a notifier or caller that is constantly called? Something like kSelectorAITrackToolCursor, if it could work with Illustrators default tools.

As for including a flex file or flash extension, I don't see how it can track the cursor's location without the plugin doing so first.  Like in the sample you supplied, kAICSXSPlugPlugSetupCompleteNotifier would be called once, when the PlugPlug setup is completed, so an event listener in the extension would be called that one time and then stop.  I would need something to keep going to track the cursor.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 16, 2014 Jan 16, 2014

Extension:

1- My biggest problem at the moment is how to track the cursor's position without making a plugin tool.

I do not know if such a thing is possible.

What you could do is:

1- Download the latest version of ExtendScript Toolkit (ESTK 3.8) available with Creative Suite 6.

2- Open the Object Model viewer.

3- Select Adove Illustrator CS6 Type Library.

4- Try to find if Cursor object. Propeties, methods?

If there is something avaible in here, you could implement what you want to do in your extension. Otherwise, I am affraid that should be done in a c++ plugin. 

Plugin:

Is there a notifier or caller that is constantly called? Something like kSelectorAITrackToolCursor, if it could work with Illustrators default tools.

Give a look at AITool.h. All tool notifiers are defined here.

Here it is somethiong that could interesting:

Sent when the tool is selected and as the cursor is moved over the

artboard with the button up. The plug-in can set the

cursor based on location or some other factor. The message data is an \c #AIToolMessage. */

#define kSelectorAITrackToolCursor     "AI Track Cursor"

You can handle cursor position in your plugin with that notifier. See the first reply I did.

Once done, you have to send the data to your extension, using csxs event.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 16, 2014 Jan 16, 2014

It is possible to track the cursor, but not through the Illustrator SDK (outside of a tool plugin, and the tool MUST be selected for that to work). You can track the mouse position using OS-level calls and then correlate them to the document position using the AIDocumentViewSuite. You'll have handle various cases (document docked or not docked) and its the document's window handle you want to track. It's not simple, its a pain, but is absolutely doable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 16, 2014 Jan 16, 2014

I noticed kSelectorAITrackToolCursor too, would the default tools send kCallerAITool and kSelectorAITrackToolCurosr though?  If they do, this will be way easier, but I think only plugin-made tools send them.  I thought about trying to use notifications with this too, but kSelectorTackCursor isn't a notification (unless you can send selectors as notifiers?)

As for OS level calles, is it possible to make them within a plugin?  I found this: http://stackoverflow.com/questions/2262516/getting-global-mouse-position-in-mac-os-x

It seems like CGEventTap would do what I want, but I'm not sure where or if I could call it in a plugin.   Maybe decare CGEventTapCreate when kSPInterfaceStartupSelector is called in AI?

An easier option maybe is to indeed just make a new AI tool or pair of tools and try to copy the functions of the selection and direct selection tools and maybe the convert anchor point tool.

I haven't lookied into defining tools yet, so that may be the next step.  Thanks for all the help!  I can't believe how difficult it is just to get an annotation with a path's length on it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 16, 2014 Jan 16, 2014

If you can get away with requiring a tool to be active, that's way, way easier. But we've been doing the OS-level trick for about 5 years now and it works, it just takes a lot more effort. I'd have to look into the Mac-side to see what it uses, I deal with the PC mostly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 17, 2014 Jan 17, 2014

Alright, hopefuly one of my last questions now.  Is there a way to add function like the Direct Selection tool to a plugin tool?  I can get achor points selected, but I can't move the points or adjust the handles with the plugin tool.  I'm thinking listening for kSelectorAIToolMouseDrag would be involved, but I don't see any functions in AIPathSuite, AIArtSuite or AITransformArtSuite that would allow me to change individual anchor point positions or adjust their handles. 

I would also appreciate a point in how to track scrolling to change the coordinates of already displayed annotations, but that isn't really urgent.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2014 Jan 19, 2014
LATEST

Okay, I've finished my Plug-in to a point where I can use it.  I decided to forego being able to select with it and instead set it to a keyboard shortcut so I can quickly switch between selection tools and the plugin tool.  What I finished with tells me the length of the segments of a path along with the overall length of the path just by mouseing over the path with the tool.

For possible future references, this topic (eventhough it's a few years old):  http://forums.adobe.com/message/1263552#1263552

has some stuff that could be helpful for people looking for something similar.

I'm marking Mr. Patterson's answer as correct because in the end, after searching and working at it for a week, there really isn't a simple way to track the cursor without making a tool.  If I had found this out when I started, it would have saved me quite a bit of time, so hopefully this thread will help someone in a similar situation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines