Linking Visio WBS Modeler Diagrams to Project

I have recently been asked if it is possible to update the % Complete data diagrams created with the WBS Modeler Visio 2007 Add-in (http://www.microsoft.com/downloads/details.aspx?FamilyID=34c28a49-e14c-4a7d-8d49-90061fe08ab4&DisplayLang=en).  Well, it is always possible with custom code, but it is intended that the WBS Modeler diagrams can be refreshed using the Link Data to Shapes feature in Visio 2007 Professional.  I know this because I wrote WBS Modeler, and in this article, I will tell you how.

Firstly, I will use the Commercial Construction project that is installed with the Visio SDK for this example, which I show an extract from below.

image

Then I created a new WBS Modeler diagram based on the above project.

image

I simply imported the whole project using the WBS Modeler / Import from Microsoft Office Project menu action.

image

The Element shapes are color coded according to their Outline Level by default, and they are labeled with their Outline Number and a truncated version of the Element Name shape data.  Notice that the Shape Data window shows more of the Project data fields than is displayed on the shape.

NB If you do see all of these Shape Data rows, then click on the page and ensure that the page Hide extra Project properties is set to False in the Shape Data window.

In this particular sample project, there are no costs, nor are there any non-zero % Complete values, so I’ll change some of these in the original project, then update the Visio diagram.

Therefore, I revealed the Unique ID, % Complete and Cost fields in Project.

image

I then exported the Project tasks to Microsoft Excel using File / SaveAs and Selected Data in the Project Export Wizard.

image

You then need to select the Unique ID and any other fields that you want to export.

image

You can optionally save the Map for future use, but you should end up with an Excel spreadsheet that contains the data that you requested.

image

Then, in Visio 2007 Professional, you can click Data / Link Data to Shapes and select the Excel workbook that you just created.  There should be just one region, Task_Table1$, and you should ensure that the Unique_ID column is checked.

image

When you click Finish, the Excel data is copied into the Visio document as External Data.  You must now ensure that the column labels match those on the Element shapes by opening the Column Settings dialog from the right-mouse menu of the External Data window. So, Unique_ID becomes Unique ID and Percent_Complete becomes % Complete.  This will ensure that the data is copied into existing Shape Data rows rather than creating new ones.

image

In addition, I changed the Data Type for the Cost field to String because my original Element shape is expecting a string.

image

You can then choose Automatically Link from the right-mouse menu of the External Data window, and use the All shapes on this page option.  Finally, you must ensure that the Data Column Unique ID equals the Shape Field Unique ID.

image

When the links have been created, you will probably think that something has gone wrong because everything has turned black.

image

However, this is normal because Visio has automatically assigned a Data Graphic to all the shapes, so all you need to do is edit it.  In this example, I simply deleted the two text fields that Visio had automatically created, and then added a new Data Bars for the % Complete and Cost fields, and Color By Value for the Parent Element.

I entered the Custom Formula={% Complete}*100 so that the numbers would be between 0 and 100.  You can enter these formulae by selecting More Fields at the bottom of the Data Fields drop-down list on the New Data Bar dialog.

image

I also edited the Label text and selected the position to be Center/Bottom Edge.

image

Although I set the Cost property as String for the import, Visio is still able to treat the contents as a number for the Data Graphics, so I thought a Thermometer Data Bar would be interesting.  Note that I set the Maximum Value to more than the known data values.  (See my Visio Conference blog for code on how to automatically update maxima and minima values).

image

Finally, I decided to use Color By Value on the Parent Element property rather than on the Outline Level one … just to make the diagram more interesting.

image

When all of this is applied, then you will hopefully see how much more understandable the data is when Link Data to Shapes and Data Graphics are combined in Visio 2007 Professional.

image

So,the overall effect is a linked WBS Modeler diagram that can be refreshed whenever the data is published into the Excel workbook from Project.

image

Of course, any Visio diagram that utilises Data Graphics is much enhanced by a legends for the linked recordsets, Color By Value and Icon Sets.  However, this is not available out-of-the-box, so you will have to trial (then hopefully buy) my own DataLegends add-in (http://www.bvisual.net/Products/DataLegends.aspx)

The files above are available for download at http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/CommercialConstruction.zip

Posted in Visio. 5 Comments »

Wanna See Some Visio MVPs?

Last week, Microsoft invited all worldwide MVPs to the annual MVP shindig in Seattle.  So, I thought it may be interesting for some to see what a Visio MVP looks like!

3Amigos2

Left to right – me (MVP UK), Senaj Lelic (MVP Germany) and John Marshall (MVP Canada) – the oldest and longest serving Visio MVP!

2Amigos

David Salaguinto (Microsoft), Dave Edson (MVP USA – currently), Tim Davenport (Microsoft), Graham Wideman (MVP USA/Canada), and Dan Albertson (Microsoft).

3Amigos

Senaj Lelic (again), Al Edlund (MVP USA) and Chris Roth (MVP USA/Austria/Germany/…)

We would like to thank Microsoft Visio product team for two very enjoyable days on campus (trying to beat the Outlook guys to the food), and I’m sure they really do appreciate our feedback!

Posted in Visio. 2 Comments »

Setting Visio Shape Cell Values By Connections

A recent newsgroup poster asked me to explain how to set the line color and weight of a connector according to the shapes it is connected to.  So, in this article, I have tried to explain one method of achieving this with minimal external coding.

In this example, I have created a rectangle shape that has a single Shape Data row, MyData, which has a fixed list of values, A;B;C.

The connector shape has been modified to trigger an event whenever a connection is made or unmade.  If the user successfully connects two rectangles with the same MyData value, then the line (weight and color) of the connector shape is amended to match the rectangle shapes.

image

The diagram below attempts to explain the relationships between the cells in the rectangle, connector and page.

image

The red arrows indicate the values updated by the VBA code; the green arrows indicate the values referenced from the page shapesheet, and the blue arrows indicate the values referenced within the same shapesheet.

Page

I modified the page shapesheet to have three new User-defined rows in order to have a centralised list of possible data values, and the corresponding line weights and colors for each value.  This is done with a simple semi-colon separated list, which could have been updated from an external data source.

User.MyDataList="A;B;C"

User.MyLineWeights="1pt;2pt;3pt"

User.MyLineColors="RGB(255,0,0);RGB(0,255,0);RGB(0,0,255)"

In fact, these page cells could be inserted into the Master page of both the Rectangle and Connector shape (as in the sample diagram available below) and the act of dropping either master onto a new page will have the effect of duplicating these cells in the page shapesheet.

Rectangle

Then I modified a rectangle to have a new Shape Data row (Prop.MyData), where the format cell referenced the page User.MyDataList cell.

Prop.MyData.Format=ThePage!User.MyDataList

image

The line weight and color of the rectangle is changed with the following formulae:

LineWeight=GUARD(INDEX(LOOKUP(Prop.MyData,Prop.MyData.Format),ThePage!User.MyLineWeights))

LineColor=GUARD(INDEX(LOOKUP(Prop.MyData,Prop.MyData.Format),ThePage!User.MyLineColors))

Dynamic Connector

Now, in order to get the connector shape to fire an event whenever the connector shape is connected or disconnected, it is necessary to call a bit of code, ConnectIT, whenever the value in the BegTrigger or EndTrigger changes.  These cells are automatically updated whenever a connect or disconnect is done.

User.ConnectITTrigger=DEPENDSON(BegTrigger,EndTrigger)+CALLTHIS("ConnectIT","")

User.BegIdx=0

User.EndIdx=0

I amended the LineWeight and LineColor formulae to respond to values in the User.BegIdx and User.EndIdx cells.

LineWeight=THEMEGUARD(IF(AND(User.BegIdx=User.EndIdx,User.BegIdx>0,ISERRVALUE(BeginX)=FALSE,ISERRVALUE(EndX)=FALSE),INDEX(User.BegIdx,ThePage!User.MyLineWeights),IF(CELLISTHEMED(FALSE),THEME("ConnectorWeight"),SETATREFEXPR(THEME("ConnectorWeight")))))

LineColor=THEMEGUARD(IF(AND(User.BegIdx=User.EndIdx,User.BegIdx>0,ISERRVALUE(BeginX)=FALSE,ISERRVALUE(EndX)=FALSE),INDEX(User.BegIdx,ThePage!User.MyLineColors),IF(CELLISTHEMED(FALSE),SETATREFEXPR(THEME("ConnectorColor")),SETATREFEXPR(0))))

The bold characters are those bits that I added into the existing LineWeight and LineColor formulae, in order to check that the index of the values of the rectangle shapes at either end match each other.  If they do, then the line is changed too.

The ISERRVALUE(BeginX)=FALSE and ISERRVALUE(EndX)=FALSE part trap the changes due to either rectangle from being deleted.

VBA Code

Whenever the code is called, it clears the values in the User.BegIdx and User.EndIdx cells, then sets a formula to return the index of the value in the connected rectangle shapes, if they exist.

The following subroutine was added to a new module in the VBA project of the document:

Public Sub ConnectIT(ByVal shp As Visio.Shape)

If Visio.Application.IsUndoingOrRedoing Then
    Exit Sub
End If
Dim cnx As Visio.Connect
shp.Cells("User.BegIdx").Formula = "0"
shp.Cells("User.EndIdx").Formula = "0"
For Each cnx In shp.Connects
    If cnx.ToSheet.CellExists("Prop.MyData", Visio.visExistsAnywhere) Then
        If cnx.FromCell.Name = "BeginX" Then
            shp.Cells("User.BegIdx").Formula = _
                "=LOOKUP(Sheet." & cnx.ToSheet.ID & _
                "!Prop.MyData,ThePage!User.MyDataList)"
        ElseIf cnx.FromCell.Name = "EndX" Then
            shp.Cells("User.EndIdx").Formula = _
                "=LOOKUP(Sheet." & cnx.ToSheet.ID & _
                "!Prop.MyData,ThePage!User.MyDataList)"
       
End If
    End If
Next

End Sub

Consequently, the connector shape responds to connections, disconnections and data changes in the connected rectangle shapes.

You can download the sample drawing here: http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/ConnectTrigger.vsd or http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/ConnectTrigger.zip

Follow

Get every new post delivered to your Inbox.

Join 45 other followers