共用方式為


What's New in Visio 2010 for Automation Developers

Microsoft Visio 2010 provides a powerful single platform for your custom drawing solutions. New Automation objects, collections, properties, methods, enumerations, and events, along with new ShapeSheet cells and functions, give you more options for defining the behavior of the elements in your solutions.

New features for Automation developers in Visio 2010

Among the new features of interest to developers that expose APIs in Visio 2010 are the ribbon; containers, callouts, and lists; diagram validation; subprocesses; incremental shape alignment and spacing; automatic page sizing; publishing as VDW files; connectivity; and raster export. This topic gives a brief summary of each of these features and mentions some of the new Visio objects and members that are associated with the features and exposed in Visual Basic for Applications (VBA). For more complete explanations of some of these features and accompanying code samples, see the MSDN Visio Developer Center.

Note

Visio objects and members that are associated with diagram validation and subprocesses are available only to licensed users of Microsoft Visio Premium 2010. Visio objects and members that are associated with publishing as VDW files are available only to licensed users of Microsoft Visio Professional or Premium 2010.

The ribbon

The most obvious change in Visio 2010 is the adoption of the ribbon component of the Office Fluent user interface, which takes the place of the system of layered menus, toolbars, and task panes that existed in previous versions of Visio. The CommandBar object and related objects and members in the Office type library, and the UIObject object and related objects and members in the Visio type library, that you used to customize the user interface in previous versions of Visio are still available in Visio 2010, but they function differently. When you run VBA code that was designed to customize the user interface of previous versions of Visio, Visio 2010 responds by placing your customizations on a new ribbon tab called the Add-Ins tab.

For example, if running your code in Microsoft Office Visio 2007 adds a command to a built-in menu, running that same code in Visio 2010 displays the Add-Ins tab (if you have not already displayed it by running some other code) and adds your command to a group called Menu Commands.

Likewise, if running your code in Visio 2007 adds a button to a built-in toolbar, running that same code in Visio 2010 also displays the Add-Ins tab (if you have not already displayed it) and adds your button to a group called Toolbar Commands.

Although you cannot use legacy code to programmatically customize the ribbon beyond adding the Add-Ins tab, you can use the new Document.CustomUI property to store ribbon customization in a document and the Application.RegisterRibbonX and Application.UnregisterRibbonX methods to register and unregister, respectively, an IRibbonExtensibility interface that is implemented by an add-on to populate the custom user interface.

Structured diagrams: containers, lists, and callouts

Structured diagrams are Visio 2010 drawings that are organized by using containers, lists, and callouts.

Containers are shapes that visually contain and logically relate other shapes on the page. They typically have a visible boundary around their contents, and they may have a text heading. They offer special behaviors for working with the shapes they contain.

You can use the Page.DropContainer method to drop a new container on the drawing page. Then, you can use the ContainerProperties property of the returned Shape object to get a ContainerProperties object. Then you can use the following methods and properties of that object, among others, to work with containers programmatically: AddMember, Disband, FitToContents, GetMargin, GetMemberShapes, RemoveMember, SetMargin, ContainerStyle, LockMembership, and ResizeAsNeeded.

Lists are special types of containers whose members form ordered sets of unconnected shapes. Lists are found in diagrams such as cross-functional flowcharts and wireframe diagrams, as well as in data-graphic legends.

To work with lists programmatically, you can use the Page.DropIntoList method, as well as the following methods and properties of the ContainerProperties object: GetListMembers, GetListMemberPosition, GetListSpacing, InsertListMember, ListAlignment, ListDirection, ReorderListMember, and SetListSpacing.

Note

By default, the logical relationships between containers, lists, and their members will not be preserved when shapes are manipulated programmatically. To enable your diagram to maintain relationships between shapes, you must set the Document.DiagramServicesEnabled property to a value that includes visServiceStructureBasic or visServiceStructureFull. To enable your diagram to maintain and form new relationships between shapes, you must set the Document.DiagramServicesEnabled property to a value that includes visServiceStructureFull.

Callouts are descriptive shapes that you can associate with other shapes in the drawing.

To create a new callout programmatically, you can use the Page.DropCallout method. You can use the CalloutTarget, and IsCallout properties of the Shape object to access information about callouts and their associated targets. You can also use the CalloutsAssociated property of the Shape object to determine whether the specified shape has callouts associated with it.

Diagram validation

Diagram validation is a feature that lets you analyze a diagram to verify that it is properly constructed and is compliant with any business logic defined for the document. When a diagram is validated against a set of defined rules, any errors found are presented to users; users can then fix or ignore these errors, as they see fit.

Several new objects are exposed in Visio 2010 that, along with their members, make it possible to validate diagrams programmatically, including the Validation object, ValidationRuleSets collection, ValidationRuleSet object, ValidationRules collection, ValidationRule object, ValidationIssues collection, and the ValidationIssue object.

Subprocess diagrams

Subprocess diagrams make it possible for users to extract a set of shapes from a business-process diagram, such as a flowchart, and move those shapes to a separate Visio page, linked to the main diagram. It is possible to link subprocess diagrams to individual shapes in the main business-process diagram.

To create subprocess diagrams programmatically, you can use the Shape.CreateSubProcess object, or alternatively, the Shape.MoveToSubprocess or Selection.MoveToSubprocess method.

Connectivity

New methods of the Page and Shape objects let you manipulate and traverse connected diagrams or graphs at a higher level of abstraction than you could previously. You can use the Shape.ConnectedShapes method to get the IDs of shapes at the other end of a connector from a given shape. You can use the Shape.GluedShapes method to get the IDs of the shapes that are directly glued to a given shape. Use the Shape.Disconnect method to unglue and offset connectors from the specifed shape.

You can also use the DropConnected, SplitConnector, and AutoConnectMany methods of the Page object to create a new, connected shape, split an existing connector with a shape you specify, and automatically connect several specified shapes on the page, respectively.

Configuring raster export

In Visio 2010, you can get and set output options for export of Visio diagrams in raster file formats (PNG, GIF, TIFF, JPG, and BMP) programmatically.

You can use methods of the ApplicationSettings object to get and set raster-export resolution and size, and you can use properties of that object to get and set raster export attributes such as data format, data compression, color reduction, color format, background color, transparency, and quality, among others. You can use these methods and properties in conjunction with the existing Page.Export and Selection.Export methods to export a diagram in a raster file format.

Page Auto Size

When the Page Auto Size feature in Visio 2010 is enabled, Visio automatically adds or removes printer-paper size tiles to the drawing, as necessary, to best fit the drawing to the shapes on the page.

To enable or disable this feature programmatically and specify whether Visio automatically resizes the page as shapes are added and removed, set the Page.AutoSize property to True or False. Note that if AutoSize is currently set to False, setting it to True will not automatically resize the page immediately. You can, however, use the Page.AutoSizeDrawing method at any time to resize the page to ensure that all the shapes in the diagram are on it.

To enable this feature for shapes that are manipulated programmatically by solutions, set the Document.DiagramServicesEnabled property to a value that includes visServiceAutoSizePage.

Incremental shape alignment, spacing, and placement direction change, and moving shapes off page breaks

In Visio 2010, you can programmatically make incremental changes to the alignment, spacing, and placement direction of all shapes in a selection or all shapes on the page. In addition, you can move shapes off page breaks programmatically.

To accomplish incremental shape alignment, spacing, and placement direction change, and moving shapes off page breaks, use the following methods: Page.LayoutIncremental, Selection.LayoutIncremental, Page.LayoutChangeDirection, Selection.LayoutChangeDirection, Page.AvoidPageBreaks, and Selection.AvoidPageBreaks.

Publishing Visio diagrams as VDW files

In Visio 2010, you can programmatically publish Visio diagrams to Microsoft SharePoint servers as VDW files, so that users can view them without the need to have Visio installed on their computers. To do so, use the SaveAs method of the Document object, assigning the file the .vdw extension. In addition, you can programmatically set options for publishing these files.

Use the ServerPublishOptions property of the Document object to get a ServerPublishOptions object, which in turn enables you to set publish options for the document.

New members of the object model in Visio 2010

New Objects, Collections, and Enumerations

New Members and Constants

For a list of new ShapeSheet cells and functions, see the Microsoft Visio 2010 ShapeSheet Reference.

For the latest information about developing with Visio, including product news, technical articles, downloads, samples, and the Visio SDK, see the MSDN Visio Developer Center.