Calling functions in a Visio Addin in a solid manner

Started by Visisthebest, December 06, 2020, 12:54:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

In this topic:
http://visguy.com/vgforum/index.php?topic=5617.0

This solution for calling functions in you addin is proposed:

Quote from: AntmanLFE on May 03, 2014, 03:18:40 AM
Ok i went around in circles for this for quite a while as almost everything refers to an ADDON as opposed to an ADDIN.

The simplest solution i eventually stumbled upon was to create a marker event in my vsto addin.



public partial class ThisAddIn
{
        //Startup
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Register a MarkerEvent on startup
            Globals.ThisAddIn.Application.MarkerEvent += new Visio.EApplication_MarkerEventEventHandler(Application_MarkerEvent);
        }

        My custom function
        void Application_MarkerEvent(Visio.Application visapp, int SequenceNum, string ContextString)
        {
            MessageBox.Show(ContextString);
        }
}


In my shapesheet i can then use the action RUNADDONWARGS("QueueMarkerEvent","/app=MyNewAddin /args=DoSomething")
Activating this action then opens the message box and returns the ContextString of the event which in this case was "/doc=1 /page=1 /shape=Sheet.1 /shapeu=Sheet.1 /app=MyNewAddin /args=DoSomething"

Hope this helps someone in the future

But Visio Guy notes these challenges with this solution:

"I find it a pain to have to listen to marker events, parse string info, delay processing until VisioIsIdle or NoEventsPending, I wish add-in developers had the same direct-calling mechanisms that RUNADDIN, RUNADDINWARGS, and CALLTHIS offer, but MS haven't done a thing since .NET came into being."

What is needed to make sure addin functions are called in a reliable manner from a shape on which I place the user command in the shape's context menu? (Say the function is 'layout this shape's children'). I am used to CALLTHIS with VBA embedded in the stencil which is a very simple and effective solution (because my function knows which shape it was called from).

I want to avoid unpredictable behavior with addins but currently I do not fully understand the underlying mechanisms/architecture and what's going on exactly in the back and forth between the Visio application, the .NET interop and the addin, as well as aspects of the COM legacy architecture (saw it being called .net version 0 somewhere;)) that impact how the software behaves.
Visio 2021 Professional