Visio Object Model Overview
To develop Visual Studio Tools for Office solutions for Microsoft Office Visio, you can interact with the Visio object model. This object model consists of classes and interfaces that are provided in the primary interop assembly for Visio, and are defined in the Microsoft.Office.Interop.Visio namespace.
This topic provides a brief overview of the Visio object model. For information about using the Visio object model to perform tasks in Visual Studio Tools for Office projects, see the following topics:
Visio provides many objects with which you can interact. These objects are organized in a hierarchy that closely follows the user interface. At the top of the hierarchy is the Microsoft.Office.Interop.Visio.Application object. This object represents the current instance of Visio. The Microsoft.Office.Interop.Visio.Application object contains the Microsoft.Office.Interop.Visio.Document and Microsoft.Office.Interop.Visio.Page objects as well as the Microsoft.Office.Interop.Visio.Documents and Microsoft.Office.Interop.Visio.Pages collections. Each of these objects and collections has many methods and properties that you can access to manipulate and interact with it.
For more information, see the VBA reference documentation for Microsoft.Office.Interop.Visio.Application, Microsoft.Office.Interop.Visio.Document, and Microsoft.Office.Interop.Visio.Page objects, and also the Microsoft.Office.Interop.Visio.Documents and Microsoft.Office.Interop.Visio.Pages collections.
The following sections briefly describe the top-level objects and how they interact with each other. These objects include the following objects:
The Microsoft.Office.Interop.Visio.Application object represents the Visio application, and is the parent of all of the other objects. Its members usually apply to Visio as a whole. You can use the properties and methods of the Microsoft.Office.Interop.Visio.Application and the Microsoft.Office.Interop.Visio.ApplicationSettings objects to control the Visio environment.
In application-level add-in projects, you can access the Microsoft.Office.Interop.Visio.Application object by using the Application field of the ThisAddIn class. For more information, see Programming Application-Level Add-Ins.
The Microsoft.Office.Interop.Visio.Document object is central to programming Visio. It represents a drawing, stencil, or template file. When you open a Visio document or create a new document, you create a new Microsoft.Office.Interop.Visio.Document object, which is added to the Microsoft.Office.Interop.Visio.Documents collection of the Microsoft.Office.Interop.Visio.Application object.
The document that has the focus is called the active document. It is represented by the Microsoft.Office.Interop.Visio.Application.ActiveDocument property of the Microsoft.Office.Interop.Visio.Application object.
The Microsoft.Office.Interop.Visio.Page object represents the drawing area of a foreground page or a background page. You can use the Microsoft.Office.Interop.Visio.Page.Background property to determine whether a page is a foreground or background page.
To create shapes, you can use methods that include the Microsoft.Office.Interop.Visio.Page.DrawSpline and Microsoft.Office.Interop.Visio.Page.DrawOval methods. Additionally, you can retrieve masters from stencils and place the shapes on a page by using the Microsoft.Office.Interop.Visio.Page.Drop or Microsoft.Office.Interop.Visio.Page.DropMany methods.
For information about the classes you can use in the Visio object model, see the following sets of documentation. The online MSDN Library documentation provides information about the Visio object model and code samples in VBA. The Visio 2007 Software Development Kit (SDK) provides code samples in Visual Basic and C#. The Visio 2007 SDK also provides publishing tools and Visual Studio templates.
Microsoft Office Visio 2007
Microsoft Office Visio 2003
Additional Types in Primary Interop Assemblies
You can find types in the primary interop assemblies that are not visible to VBA because of implementation differences. VBA provides a view of the Visio object model that includes only the objects and members that you can use directly. The primary interop assemblies expose the same object model, but they also include other interfaces, classes, and members that translate objects in the COM object model to managed code. These additional items are not intended to be used directly in your code.
For more information, see Overview of Classes and Interfaces in the Office Primary Interop Assemblies and Office Primary Interop Assemblies.
At this time, there is no reference documentation for the Visio primary interop assemblies.
All of the objects and members in the VBA reference correspond to classes and members in the primary interop assembly that you use in Visual Studio Tools for Office projects. For example, the Visio.Application object in the Visio VBA documentation corresponds to the Microsoft.Office.Interop.Visio.Application class in the primary interop assembly.
The VBA reference has the following advantages:
It documents the object models of both Visio 2007 and Visio 2003.
It provides code examples for most members.
The VBA reference has the following disadvantages:
It provides syntax and code examples for VBA only. To use the code examples in a Visual Studio Tools for Office project, you must translate the VBA code to Visual Basic or Visual C#.