Visio Guy

Visio Discussions => Programming & Code => Topic started by: AntmanLFE on May 02, 2014, 10:55:50 AM

Title: Call addin function from shapesheet action
Post by: AntmanLFE on May 02, 2014, 10:55:50 AM
Hi All,

I have created a visio addin which i have gotten working well. I have created a ribbon with several buttons each doing a specific task.
What i would like to do now is add an action into my shapes shapesheet to provide a context menu entry and run one of the functions in my addin.

From what i can find there from searching the general way people do this is with RUNADDON("MyAddonName") in the actions.

A couple questions questions which come to mind is:
1) Does this method work with Addins? (If not is there an alternative)
2) How i able to call a specific function or accept arguments? (I assume the RUNADDONWARGS command would be for this although not sure how i would catch these arguments with an addin)
Title: Re: Call addin function from shapesheet action
Post by: Paul Herber on May 02, 2014, 12:02:41 PM
Here's an article I wrote some time ago that shows how to do this:
http://www.paulherber.co.uk/articles/visio-articles/output-dialog/ (http://www.paulherber.co.uk/articles/visio-articles/output-dialog/)
Your addin either needs to be registered as an addin or have its path included in Setup -> Advanced -> File Paths -> Addons

Title: Re: Call addin function from shapesheet action
Post by: AntmanLFE on May 02, 2014, 12:47:35 PM
Hi Paul. In that example you are calling a separate application and sending a text string via the command line arguments.

Although what i want to achieve is similar function wise, i dont want to use a separate executable file.

In my current setup i have implemented an add-in (not addon) which produces a dll file.

Am i able to call this add-in and pass it an argument which i have effectively embed into visio?
Title: Re: Call addin function from shapesheet action
Post by: 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
Title: Re: Call addin function from shapesheet action
Post by: Visio Guy on May 06, 2014, 08:58:45 PM
There is also a QUEUEMARKEREVENT ShapeSheet function, which is a bit more direct than calling RUNADDON to run an old 'que' add-on. This function doesn't give you all the caller args, though. But if you are acting on the active page or doc, or don't mind gambling that the selected shape hasn't changed in the last few milliseconds, it's fine. You can also append those same arguments to your marker using ShapeSheet concatenation.

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.
Title: Re: Call addin function from shapesheet action
Post by: walshjd on April 28, 2016, 02:13:15 PM
I tried to implement this.

I added RUNADDONWARGS("QueueMarkerEvent","/app=MyNewAddin /args=DoSomething")

as suggested to the EventDblClick of a shape.

But, when I double click the shape, nothing happens.

Is there some other step I am missing or am I making the call incorrectly?
Title: Re: Call addin function from shapesheet action
Post by: Yacine on April 30, 2016, 08:52:28 AM
Do MyNewAddin and DoSomething stand for something? If not, you'll need to replace them by the right values.