Visio 2010 Add-in
I'm writing a Visio 2010 add-in. I need to process the document and analyze all objects inside of it.
As first I got the current instance of Visio
IVisio.Application app;
object visioObject = Marshal.GetActiveObject("Visio.Application");
app = visioObject as IVisio.Applic开发者_运维问答ation;
Now, if
if (app.ActiveDocument != null)
How should I get all the elements of the active document? How should I understand the type of the element I'm analyzing? If this element is of type Entity (Object relational), how should I access all the columns definition?
Hope I cleared myself.
Thanks for eventual tips!
I would start with the Visio 2010 Automation reference, found online at:
http://msdn.microsoft.com/en-us/library/ee861526.aspx
The Visio object model is quite a large beast, that takes some time to absorb and understand. But the classes are all documented on MSDN, so you should be able to find references, examples and probably even discussion forums up there.
A document basically consists of Master shapes, and Pages. These are both containers for Shape objects. And inside of shapes, you'll find the shapesheet with its Section, Row and Cell objects. Every Cell has a formula and a value.
There's more, too, but that might be enough to get you started.
An easy way of starting might be the following unit-test, that writes all shapes and names to the console:
[TestMethod]
public void testVisio()
{
Microsoft.Office.Interop.Visio.Application visioApp = null;
try
{
//Create a new instance of Visio
visioApp = new Microsoft.Office.Interop.Visio.Application();
// Show Visio
visioApp.Visible = true;
foreach (Page page in visioApp.ActiveDocument.Pages)
{
foreach (Shape shape in page.Shapes)
{
Console.WriteLine(String.Format("Page {0}: Shape-Name: {1}", page.Name, shape.Name));
}
}
}
finally
{
//Close started application again
visioApp.Quit();
Marshal.ReleaseComObject(visioApp);
visioApp = null;
}
}
Of course you can replace the visioApp.ActiveDocument with the reference you already mentioned in your posting.
More information can be found on MSDN, e.g. http://msdn.microsoft.com/en-us/library/gg617997.aspx and generally I recommend to just play around a bit, and you will find the objects required, e.g. shapes have cells where user-properties can be stored etc. Or if not, you can ask a more specific question.
精彩评论