Call addin function from shapesheet action

Started by AntmanLFE, May 02, 2014, 10:55:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AntmanLFE

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)

Paul Herber

#1
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/
Your addin either needs to be registered as an addin or have its path included in Setup -> Advanced -> File Paths -> Addons

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

AntmanLFE

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?

AntmanLFE

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

Visio Guy

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.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

walshjd

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?

Yacine

Do MyNewAddin and DoSomething stand for something? If not, you'll need to replace them by the right values.
Yacine