Question

I am trying to open a Visio 2013 document and iterate over the flow chart objects, in sequential order, using the Visio 2013 SDK (Visio 2013 SDK), after which custom code will be implemented to write values from the flowchart objects to a text file. The goal is to be able to do all of this using C# rather than built-in VBA macros within Visio. Is this possible, and if so are there any entry point code samples available?

Was it helpful?

Solution

All you can do in VBA, you can do in C# as well (by adopting syntax of course). Means, Visio object model is equally accessible from VBA and C#. As for the code sample, it's not quite clear what you mean by "iterating in sequential order". For example, what would you do if shapes on a diagram form a cycle? It has no begin and no end.. Or a tree?

Although, you can rather easily enumerate all shapes and all connections separately:

using System;
using Visio = Microsoft.Office.Interop.Visio;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var app = new Visio.Application();
            var doc = app.Documents.Open(args[0]);

            var page = doc.Pages[1];

            foreach (Visio.Shape shp in page.Shapes)
                Console.WriteLine("shape #{0}: text: '{1}'", shp.ID, shp.Text);

            foreach (Visio.Connect conn in page.Connects)
                Console.WriteLine("connector: #{0} -> #{1}", conn.FromSheet.ID, conn.ToSheet.ID);

            app.Quit();
        }
    }
}

Take a look at these threads:

C# code to read visio shape's connectivity with other shapes in a flow chart

Traverse through every possible path in a Visio Flow-Chart with C#

Note that to simply write values from shapes to a text file, you can use "Shape Reports" button on "Review" tab. See more about "Shape Reports" in Visio:

http://www.youtube.com/watch?v=Lm1ZrkPpI1U

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top