0
votes

I've got a template that employs vba to respond to shape events. Typically, when a user double clicks a shape, a user form is displayed which they can use to edit shape data.

I'd like to convert this into a Visio AddIn using C#. Most of the general code I'm ok with, but the shape events has left me stumped !?

Google left me with a hint to download the Visio SDK and to look at 'persistent events'. Yet following the install instructions I still don't see 'persistent events' in my developer tab - and not really sure what they are and if they are what I need.

Overall it just feels severely lacking in documentation. Can anyone point me in the right direction please ?

(working with Visio 2016)

1
The SDK tools that appear in the ribbon are 'Event Monitor', 'Persistent Events' and 'Print ShapeSheet' - it sounds like it's not installed correctly. If you look under Programs and Features it should show the version - what does your's say? - JohnGoldsmith
Name: Microsoft Visio SDK 2016 Version:16.0.4288.1001 - Esby
That's curious. I guess my next question is did you install the matching version with the bitness of the application - ie x86 SDK with x86 app? If that's the case and it's still not working I would raise a question on an MS forum: social.technet.microsoft.com/Forums/office/en-US/… - JohnGoldsmith
aha ! solved this. Dumb error, I just confused 32/64 bit versions - Esby
Easily done. Glad you're all fixed on both parts. - JohnGoldsmith

1 Answers

1
votes

Do you really want to use double-click as an interaction method or are you just using this because of the double-click cell?

If you do, then I would keep using this cell, but just fire a marker event with the QUEUEMARKEREVENT ShapeSheet function and then be listening for Application.MarkerEvents.

If you want to have the form appear when right-click on a context menu item, then use the same strategy but put the function in an Action cell.

If you want the form to appear when the user just selects the shape, then you need to listen for SelectionChanged on, maybe, Window.

A question to ask is, how do you start your listening? Considering that the application will be opening other documents apart from your solution, you might want to start by listening for all DocumentOpened/Created events, then decide whether it's a document of interest and then, if it is, wire up your Application.MarkerEvent listening.

An alternative approach would be to use Persistent events. In Visio, there are a small number of events that are 'persistable'. This is an event that can be saved with the file and is then automatically wired up on opening. For example, (once your SDK is working) if you look at a template like Org Chart you'll see that it includes two persistent events:

enter image description here

These events can call only call Addons (not Addins) and in the case of the Org Chart, it's that Addon that's targeted. For your situation however, you could add the QueueMarkerEvent Addon and pass through whatever arguments you like. The reason that this is useful, is that it means that you no longer have to monitor all document events as you know that your document will fire its own events to kick things off. So you just need to listen to Application.MarkerEvents, make sure that one of you args includes a unique identifier and you can then response as you like.

Can I recommend the course links in this related post, which includes example code for Marker events being fired (from a Action in the ShapeSheet)?