AlexandrS
AlexandrS

Reputation: 51

How to get Visio shapes in vector format

Im trying to get shapes from Visio project in vector format. It is possible to do it from Visio UI, but Im unable to accomplish it programmatically. My code looks like:

foreach (Visio.Master master in doc.Masters)
{
   imageName = master.NameU;
   string imageFileName = Path.Combine(@"c:\temp", imageName);
   master.Export(imageFileName + ".svg");
} 

Function Export detects passed file extension and export shape in to this format. It works correct for any raster format like bmp png etc. I can get project's shapes as raster files w/o problems. If I pass a format like emf or wmf it also saves all files and they are actually in wmf/emf format. But they have embedded raster images, so in fact they are raster.

And the last surprise - if I pass svg extension, all exported files are empty except a few ones. These ones are really not empty svg but they show the whole visio page! Not a single shape. One svg file for every project's page. This is not what I want.

So please help me - how to get every shape in vector format from visio programmatically.

Upvotes: 0

Views: 2293

Answers (2)

Nikolay
Nikolay

Reputation: 12235

The "Export" method for a "Selection" object seems to work just fine for SVG. So you could try to workaround this issue as following:

        foreach (Visio.Master master in doc.Masters)
        {
            string imageName = master.NameU;
            string imageFileName = Path.Combine(@"c:\temp", imageName);

            var selection = doc.Application.ActivePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeEmpty);
            foreach (Visio.Shape shp in master.Shapes)
                selection.Select(shp, (short)Visio.VisSelectArgs.visSelect);

            selection.Export(imageFileName + ".svg");
        }

Upvotes: 2

Jon Fournier
Jon Fournier

Reputation: 4327

I'm not sure about Visio's ability to export just a single shape to SVG, but you could create a duplicate of your page, in terms of size and position, then copy each shape one by one, and export the page as SVG, which would give you just the shape.

You can also step through the geometry in the shapesheet and export it to SVG yourself, if you're familiar enough with the standard.

Another option is to export each shape to a simple SVG path, using the Path.Points() method, which returns an array of XY points for each stroke path in the geometry. This would create much larger paths than a clean SVG output, but it makes Visio render the paths to points for you, so you don't deal with arcs and splines etc...

Upvotes: 0

Related Questions