Skip to main content
Inspiring
August 31, 2018
Question

Annotator - how to work a basic example

  • August 31, 2018
  • 1 reply
  • 413 views

Hi,

This is my first attempt at writing plugins having previously been more of a scripter!

I have been 'hacking' the Annotator example project to have it work with other messages, e.g. when a document is opened.

What I am trying to do is draw an annotation against art items which have a certain key in their dictionary.

I managed to work out the message and dictionary parts, but am getting stuck on the annotator, which is producing an exception when I try to set the background colour.

Here are the changes that I made to the sample project:

1) Commented out the calls to the existing draw annotation functions

2) Upon initialisation of the plugin, set the annotator to active straight away (no need to click on the annotator tool)

3) Added a new event listener for document open

4) Set a const AIRGBColor for the background colour (exact copy/paste from the example)

5) Cast the notifier message as an AIAnnotatorMessage: AIAnnotatorMessage* annMsg = (AIAnnotatorMessage*)message;

6) Invalidate whole document bounds (as this is just a test)

7) attempt to set the background colour: sAIAnnotatorDrawer->SetColor(annMsg->drawer, BKGND_COLOR).

Everything is fine until 7) where I get an exception; EXC_BAD_ACCESS (code 1).

Inspecting the annMsg object it does have a drawer object within it, so that part seems OK.

Clearly, I'm doing something wrong prior to point 7, I have tried to work back the existing example and things seem to be called in a similar order, but does anybody have any clues as to what I might check?

Also could somebody explain what the "SDK_ASSERT" call does, as I cannot find any mention of this in the documentation?

Many thanks in advance

This topic has been closed for replies.

1 reply

Inspiring
August 31, 2018

OK, so for the benefit of anybody in the same situation, I think I know where I went wrong here.

I was trying to simply cast the message (which was not an annotator message) to an annotator message.

What I had not grasped is how the messaging works for annotators.

As far as I understand it now (feel free to correct me if wrong):

- You have to invalidate an area of the screen where you want to draw an annotation

- This will create an annotator message which you need to listen for; the handler for this can then use the drawer within the message to produce the annotation.

- You have to store the info that you want to pass to the annotator somewhere; in the case of the example it's in private variables within the annotator class, which seems as if it may have some limitations (what if you need to create a bunch of annotations for several art items - how will you know which message relates to which art item?)

After changing things to reflect the above, it does work and the exception is no longer thrown.