3 Replies Latest reply on Oct 27, 2016 10:30 AM by btempleton1982

    Redrawing art in response to kAIArtPropertiesChangedNotifier

    btempleton1982 Level 2

      So I posted the following in this questionStrange things happen when calling win32 api . But since its not strictly related to that question, I'd like to post what I've discovered in its own thread.


      I have a plugin art that I'm trying to keep synced with the contents of the artboard.


      As a result, I am modifying art in response to kAIArtPropertiesChangedNotifier. As you would expect, this pattern results in my plugin being notified of changes to the art in an infinite cycle.


      The solution seems to somehow determine whether the art actually needs to be modified, but I'm not really sure how to go about that when the notifier contains basically zero useful information.



      minimum99 responded:


      There are many way to determine if art is modified. You need to determine, inside kAIArtPropertiesChangedNotifier what arts are selected, then determine if its properties has changed. Depending on what properties you want to compare, you need to keep track of those properties using art dictionary.


      "As you would expect, this pattern results in my plugin being notified of changes to the art in an infinite cycle."

      Infinite cycle should never happen if you keep track of art properties and compare inside kAIArtPropertiesChangedNotifier as mentioned above.


      I have used kAIArtPropertiesChangedNotifier to detect if an art is deleted, moved, duplicated etc. True, kAIArtPropertiesChangedNotifier does not give us any info. we have to keep track its before and after information. Only through before and after comparison of its properties, can you determine what has changed.


      That looks like a reasonable suggestion, but I've found a way that seems to work better in my particular case.


      Whenever I draw my plugin art, I record the "Global Time Stamp" reported by AIArtSuite->GetGlobalTimeStamp() in the document dictionary.


      Then, in response to kAIArtPropertiesChangedNotifier, I retrieve the new Global Time Stamp and compare with the time stamp I recorded when I last refreshed my plugin art. If these are different, I assume that there are more recent changes to the document than my changes to the plugin art. I redraw my art only if the timestamps are different, indicating that there have been changes since I last drew my art.


      This seems to work pretty well for my case, since I don't actually care what changed, only that something changed.


      I haven't tested with multiple documents open, while making changes to both.

        • 1. Re: Redrawing art in response to kAIArtPropertiesChangedNotifier
          LeoTaro Level 4

          Sounds good. The only drawback is that GetGlobalTimeStamp was added at CC 2015.3. GetArtTimeStamp has been around since CS6. I wonder if this is updated whenever any child art changes. If so you could probably just do GetFirstArtOfLayer for each layer and check the timestamp for CS6 to CC 2015.

          • 2. Re: Redrawing art in response to kAIArtPropertiesChangedNotifier
            btempleton1982 Level 2

            GetArtTimeStamp takes a AIArtTimeStampOptions which can be kAITimeStampOfArt, kAITimeStampOfChildren, kAITimeStampMaxFromArtAndChildren. So it seems like that should cover what you're talking about.


            I did check with multiple documents open and everything seems to work fine. A kAIArtPropertiesChangedNotifier is sent when each document is brought to the front, but, for my purposes, triggering a redraw is fine at that point.


            One thing I've noticed with my method is that kAIArtPropertiesChangedNotifier is triggered while the user is editing text. I'm going to have to find a solution, since it does cause some lag as each character is entered. Is there a method to determine if the user is currently entering type in a text frame art?

            • 3. Re: Redrawing art in response to kAIArtPropertiesChangedNotifier
              btempleton1982 Level 2

              Wow, these artwork update notifiers don't seem to fire in a consistent way. I've done some more testing and it looks like my lagging text input problem goes away if I do my updates in response to kAIArtSelectionChangedNotifier instead of kAIArtPropertiesChangedNotifier. Though they both seem to fire together most of the time? The message data "count" that comes along with both of these notifiers is the same when they both fire, so that's one way to ignore one or the other.


              The docs don't say too much about the differences between the two notifiers.