Reader small image

You're reading from  Microsoft Visio 2010 Business Process Diagramming and Validation

Product typeBook
Published inJul 2010
Reading LevelIntermediate
PublisherPackt
ISBN-139781849680141
Edition1st Edition
Languages
Right arrow
Author (1)
David Parker
David Parker
author image
David Parker

David J Parker's background has been in data visualization ever since he struggled to produce lists of hospital equipment from Computer Aided Design models of buildings as a budding architect in the '80s. He moved into building and infrastructure asset management in the late '80s using a Unix system and gradually migrated to Windows-based systems throughout the '90s. He became a European Business partner of Visio Corporation in 1996 and presented the database-linked Visio solutions that he was providing merchant banks in London and New York with at several international conferences. David started bVisual Ltd. in 1998, which provides Visio-based solutions to various industries, and became a Silver-level Microsoft partner. He has been a Microsoft MVP (Visio) for the last 12 years and has helped Microsoft Corp, UK and Western Europe, by providing Visio solutions, training, website content, and presentations. David has had several books on Visio published and has been presenting Visio/SharePoint integration courses for many years for Microsoft Western Europe, from Oslo in the North down to Lisbon in the South. He has presented at SQL and SharePoint Saturday conferences and writes a regular blog for people interested in Microsoft Visio.
Read more about David Parker

Right arrow

Chapter 2. Understanding the Microsoft Visio Object Model

Whatever programming language you code in, you need to understand the objects, properties, methods, relationships, and events of the application that you are working with. Without this knowledge, the development process is slow and any code you use is going to be inefficient. Visio is no different, in that it provides the Visio Type Library with all of its elements, but Visio also has a programmable ShapeSheet behind every shape. Therefore, the Visio Type Library can only be used efficiently if you understand the ShapeSheet, and in turn, the ShapeSheet formulae can only be used fully if you understand the Visio Type Library.

Also, if you are going to create validation rules to check the relationships and properties of structured diagrams, then you will need to understand how to traverse the Visio object model.

Therefore, this chapter is going to explain the Microsoft Visio 14.0 Type Library (VisLib.dll), and the key objects, collections...

The Visio Type libraries


The publicly displayed version number of an application like Visio can be quite different from the internal version number that is revealed to programmers. For example, Microsoft Visio 2010 is the public version number for the internal version number 14. Therefore, programmers need to know that the Visio Type Library version is 14, although their users will know it as Visio 2010.

Note

There were no 13 versions prior to 14 because Visio was at version 6 (externally Visio 2000) when Microsoft bought the company in 1999. At that time, Microsoft Office was internally at version 9, so Microsoft Visio 2002 was internally hiked up to version 10 to be at the same version number as Microsoft Office 2002. At this point, Microsoft Visio 2003 was internally version number 11, and Microsoft Visio 2007 was internally 12. Version 13 went the same way as the thirteenth floors in high-rise buildings in the States—pandering to the superstitions of the masses.

Microsoft Visio 2010 may...

But all I need is the object model


Some programmers think that Visio is present just to provide a graphical canvas with symbols and lines that they need to manipulate or interrogate. Perhaps they have been used to draw items in Windows Forms applications or even XAML-based development with WPF or Silverlight. To think like this is to misunderstand Visio because Visio has a rich diagramming engine, coupled with the ability to encapsulate data and custom behaviors in every element, not to mention the inheritance between certain types of objects. This has resulted in a fairly complex structure in parts of the object model, so that all of the desired functionality can be described fully.

Programmers who look at the Visio object model for the first time may be full of pre-conceptions and look in vain for the X and Y coordinate of a shape on a page. They are surprised and a little frustrated that the X coordinate of a shape on a page is:

shape.CellsSRC(VisSectionIndices.visSectionObject,
visRowIndices...

Types of Visio document


Before we get into the object model, we need to remind ourselves of the formats and types of Visio documents. Traditionally, Visio used its own binary format (which usually has an extension *.vsd for drawings), and then the XML format was introduced (*.vdx for drawings). The latter is approximately ten times larger in size than the former, although it often compresses to be smaller than the binary equivalent. The XML format is very verbose because it needs to describe the complexity of the graphics and the inheritance of elements within the document. In addition, it is not in the same zipped-up XML files in sub-folders format as most of the Microsoft Office applications.

The Visio Web Drawing is new in Visio 2010, which, when published to SharePoint 2010, allows certain elements that are linked to data recordsets to be automatically refreshed when the underlying data is updated, without using Visio. This Visio Services feature however, does not enable new shapes to...

Which programming language should you use with Visio?


Microsoft Visio comes with Visual Basic for Applications (VBA) built into it, which is a very useful interface for exploring the object model, and testing out ideas. In addition, Visio has a macro recorder that can provide a quick and dirty way of exploring how some of the actions are performed. However, the resultant code from the macro recorder can be very verbose in parts, and completely miss out some bits because Visio is running code inside one of the many Add-ons or COM add-ins that may be installed.

If you want to use VBA then you will need to run Visio in Developer Mode by checking the option available from the Visio Options dialog (use File | Options to display this), in the Advanced group.

Developer Mode will also add some features to other parts of the Visio interface, such as additional options on the right-mouse menu when a page and shape is selected.

The Drawing Explorer window


The Drawing Explorer window can be opened in the Visio UI in the Show/Hide group on the Developer tab. It is an extremely useful method for visually navigating some of the collections and objects in the Visio application.

It starts with the active document object, and displays the Masters, Pages and Shapes collections, amongst others.

Note

There are two different page collections, Foreground Pages and Background Pages. You will normally find all of the interesting shapes in the Foreground Pages collection, since the Background Pages are usually used for backgrounds and titles.

The Visio object model


We will now examine some of the key properties of the main objects in the Visio Type Library. Please note that I have highlighted the collections in the diagrams of these objects.

Note

I have also formatted the output in the following code examples as a table for legibility, because the text will mostly wrap within the Immediate Window.

The Application object

The Application object is the root of most collections and objects in Visio, including the Active objects, two of which are useful for traversing structured diagrams—ActiveDocument and ActivePage.

The following sub-function in VBA prints out the salient information to the Immediate Window:

Public Sub DebugPrintApplication()
Debug.Print "DebugPrintApplication"
With Visio.Application
Debug.Print , "ActiveDocument.Name", .ActiveDocument.Name
Debug.Print , "ActivePage.Name", .ActivePage.Name
Debug.Print , "Addons.Count", .Addons.Count
Debug.Print , "COMAddIns.Count", .COMAddIns.Count
Debug.Print , "CurrentEdition",...

Connectivity API


All of the above sections were to get you used to the object model a bit, so that you can understand how to traverse a structured diagram and retrieve the information that you want. The Connectivity API also provides easy methods for creating and deleting connections, but we are simply interested in traversing connections in order to check or export the process steps to another application.

Here is the top part of my Write Chapter Sub-process page which demonstrates some of the key features of the Connectivity API. They are done in the following sequence:

  1. 1. The flow shapes are connected together creating a logical sequence of steps.

  2. 2. Some steps have an associated callout with extra Notes.

  3. 3. Some steps are within a Container shape to define the Phase.

Now we will traverse the diagram in code, and list out the steps in their phases with any associated notes, but first we need to understand a few of the new methods in the Connectivity API.

The Shape.ConnectedShapes method...

Summary


In this chapter, we delved into the Visio object model, and looked at the hierarchy of the objects and collections.

We looked at the analytical parts of the Connectivity API, which enabled us to navigate connections and to retrieve surrounding containers and associated callouts.

We also used this knowledge to build a function that does some rudimentary checks of a diagram structure, and to list the steps in a process flow.

In the next chapter, we will look into the ShapeSheet and how to use the functions within it.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Microsoft Visio 2010 Business Process Diagramming and Validation
Published in: Jul 2010Publisher: PacktISBN-13: 9781849680141
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
David Parker

David J Parker's background has been in data visualization ever since he struggled to produce lists of hospital equipment from Computer Aided Design models of buildings as a budding architect in the '80s. He moved into building and infrastructure asset management in the late '80s using a Unix system and gradually migrated to Windows-based systems throughout the '90s. He became a European Business partner of Visio Corporation in 1996 and presented the database-linked Visio solutions that he was providing merchant banks in London and New York with at several international conferences. David started bVisual Ltd. in 1998, which provides Visio-based solutions to various industries, and became a Silver-level Microsoft partner. He has been a Microsoft MVP (Visio) for the last 12 years and has helped Microsoft Corp, UK and Western Europe, by providing Visio solutions, training, website content, and presentations. David has had several books on Visio published and has been presenting Visio/SharePoint integration courses for many years for Microsoft Western Europe, from Oslo in the North down to Lisbon in the South. He has presented at SQL and SharePoint Saturday conferences and writes a regular blog for people interested in Microsoft Visio.
Read more about David Parker