Visio Guy

Visio Discussions => Programming & Code => Topic started by: mearturo on June 05, 2018, 09:04:27 AM

Title: C# add swimlane - Visual Studio 2017
Post by: mearturo on June 05, 2018, 09:04:27 AM
Dear all

I am using Visual Studio 2017 community edition, and I need to create a workflow with C#.

My code looks like this:

            application = new Microsoft.Office.Interop.Visio.Application();
            //application.Visible = false;
           
            application.Documents.Add("");
            docs = application.Documents;
            stencil = docs.OpenEx("BASFLO_U.VSTX", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
            page = application.Application.ActivePage;

            master = stencil.Masters.get_ItemU(@"Swimlane");

However, when I run the code at the last statement I get the message:

System.Runtime.InteropServices.COMException: 'Object name not found.'

Any ideas will be really appreciated.
Title: Re: C# add swimlane - Visual Studio 2017
Post by: Paul Herber on June 05, 2018, 03:20:02 PM
A few problems with your code.
You have opened a new template and referred to it as a stencil. However, there is no Swimlane shape in the Basic Flowchart stencil.
You need to open the Cross-functional stencil.
The folloowing code is untried...

application = new Microsoft.Office.Interop.Visio.Application();
Document doc = application.Documents.Add("");
Document stencil = doc.OpenEx("XFUNC_U.VSSX", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
Page pagObj = application.Application.ActivePage;
Shape shpObj = pagObj.drop("Swimlane", x, y); // x, y are the coordinates to drop shape at

Title: Re: C# add swimlane - Visual Studio 2017
Post by: mearturo on June 05, 2018, 03:52:59 PM
Hello

That is correct, that was the issue.

Thanks a lot