More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  bVisualPhotosProfileFriendsMore Tools Explore the Spaces community

bVisual

be smart, be clear, be visual!

bVisual

View spaceSend a message
Occupation:
Age:
Location:
Interests:
Building architect turned software application developer
Do unto others as you would have others do unto you
View space
Aviv
View space
Visuals

July 25

Hyperlinks to SharePoint Lists from Visio Shapes

My previous post showed how to link Visio Timelines to a SharePoint Calendar ( http://bvisual.spaces.live.com/blog/cns!3350D61BC93733A9!552.entry ), and I glibbly mentioned how you can create hyperlinks automatically on the shapes from the SharePoint list.  Well, that was true, but the example shown goes to a SharePoint page, and it didn’t work.  So, I feel I need to demonstrate a fix for it.

image

The ShapeSheet formula in the hyperlink address cell is:

image

=SETATREF(Prop._VisDM_Encoded_Absolute_URL)

This translates to the URL:

http://www.wssdemo.com/Lists/Calendar/1_.000

Well, this does not actually work from Visio, but, navigating to the entry in the SharePoint calendar shows that the actual URL is:

http://www.wssdemo.com/Lists/Calendar/DispForm.aspx?ID=3&Source=http%3A%2F%2Fwww%2Ewssdemo%2Ecom%2FLists%2FCalendar%2Fcalendar%2Easpx%3FCalendarDate%3D25%252F12%252F2006

… and this can be reduced to:

http://www.wssdemo.com/Lists/Calendar/DispForm.aspx?ID=3

So, how can we correct the URL for the Visio shapes?

We will need to write a little bit of code to change the formula in the hyperlink Address cell to :

=REPLACE(Prop._VisDM_Encoded_Absolute_URL,LEN(Prop._VisDM_Encoded_Absolute_URL)-4-LEN(FORMAT(Prop._VisDM_ID,"#")),LEN(FORMAT(Prop._VisDM_ID,"#"))+5,"DispForm.aspx?ID="&FORMAT(Prop._VisDM_ID,"#"))

This will change the URL to actually open the SharePoint page, like this:

image

I will write the code when I can get my Office programs working again….

July 24

Using SharePoint Calendars with Visio Timelines

I was recently asked if it is possible to use SharePoint calendars with Visio Timeline Shapes automatically.  My first reaction was “not without code”, but a closer inspection reveals that you can use Visio 2007 Professional Link Data to Shapes quite easily….

Firstly, I found the WSS Demo site http://www.wssdemo.com/application/default.aspx to be useful.

In Visio 2007 Professional, you can use Data / Link Data to Shapes … to get data from Microsoft Windows SharePoint Services:

image

Then enter http://www.WSSDemo.com (or your own) as the Site.

image

And login of course, in this case the password is pass@word1.

image

Then select the Calendar list:

image

Now, you need to rename the Title, Start Time and End Time columns by selecting Column Settings …  on the right mouse menu of the External Data window…

image

.. to Task Name, Start and Finish .  This is important, because this will be used to match the values from the calendar to the shape properties.

image 

Drag and drop a Timeline shape, and set the Start and Finish to your requirements….

image

Then, select an Interval shape in the stencil, and drag a row from the External Data window, and drop it on the page (not over the Timeline itself). The Configure Interval dialogue will popup, which you can just OK.

image

In addition to the three columns that we previously mapped, all of the other columns will be automatically added as  extra Shape Data rows on each shape.

image

Of course, you can use Milestones or Intervals….

image 

Q.E.D.

Post script:

The sample data happens to include hyperlinks as text, but you can ensure that Visio interprets them as real hyperlinks by checking the Hyperlink box on the Types and Units dialogue opened from the Data Type… button on the Column Settings dialogue.

image

You will then get hyperlinks on your shapes!  And you can have multiple ones per shape!

image

Ye gads … Visio is cool!

July 13

Flags of the World

I was recently asked how to add a country flag to Visio Org Chart shapes automatically.  Well, as I am currently working with world data at the moment, I have taken up the challenge.  Firstly, the CIA have an excellent source of information, called the World Factbook ( https://www.cia.gov/library/publications/the-world-factbook/ ).  You can find all sorts of information about every country in the world, including, of course, their flags.  There are over 240 countries at the moment, and there are various codes used by different systems to identify them.  Even the name may not be the same, for example, do I live in UK, United Kingdom, Great Britain, United Kingdom of Great Britain and Northern Ireland or just plain old England?  Answers on a post card, please, addressed to …..?

Alternatively, a country can be identified accurately with a code, but you need to know which system is being used.  United Kingdom can be identified by GB in the Iso 2 character system, or 826 in the Iso numeric system, or UK in the FIPS 10 system.  The CIA World Factbook utilises the FIPS 10 code, so consequently, all of the country related web pages and images are coded with this system.

I have already created an Access database with all this information, so I decided to use this knowledge to create a Flags of the World Visio Master.

image

I wrote some VBA to download the gif files from CIA website, and imported them into a specially prepared group shape.  Each image shape was automatically named with the FIPS 10 code, and the Width and Height formulae were written to be 0 if the parent group shape does not represent relevant country.

image

The ShapeSheet of the parent shape was loaded with semi-colon separated lists of country related data, mainly pulled from the CIA website.  The Prop.Country Shape Data row is a fixed list so that the user can select a country by its name.  The other Shape Data rows are all guarded because their values are pulled via the Index of selected country name, from the User defined cells.

image

ShapeSheet of the GB sub-shape, below, showing that the Width and Height is 0, if the shape Name is not equal to the Prop.Fips10 value in the parent shape.  Notice that the Width and Height formulae maintain the original aspect ratio of the flag image.

image

This provides a Flags of the World Master, but I also created a Flags of the World Small Master because the first one uses the large flag images from the CIA website, but the second one uses the small image files, and thus uses less file size.

image

I have also added context sensitive hyperlinks to the CIA website, Maps Live, Google Maps and Google Earth, and one to bVisual’s website….

OK, now we are halfway there … we actually want to apply the map icon to any shape that has a Shape Data value that is a country name, but we don’t know the name of this Shape Data row in advance….

Visio 2007 Professional Data Graphics has Icon Sets, but you can only have a maximum of 5 icons in each set … certainly not enough for over 240 countries.  So, why not use an Icon Set as a placeholder for a country flag, then replace the Icon Set image with the flag for the country whose value is in the Shape Data row specified by the Icon Set Graphic Item?

That is exactly what I did in the screen-shot below:

image

I duplicated an existing Icon Set (Trend Arrow 1) in the Drawing Explorer, renamed it as FlagPlaceholder, then amended it to have one image sub-shape, called Flag.

image

Thus the Icon Set becomes available in the Data Graphics editor, and you can select the Shape Data row that contains the name of the country.  You only need to have one qualifying value, so I entered does not contain * , because I assume that there is no country in the world with that character in its name.

The attached stencil, FlagsOfTheWorld.vss http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/FlagsOfTheWorld.zip , includes the macro UpdateFlags, which will then change the flag for each selected shape.

image

So, when the macro is run, the test shapes now show the flags for each country….

image

Option Explicit
'David Parker
'July 2008
'No warranties at all with this code
'Use at you own risk

Public Sub UpdateFlags()
Dim shp As Visio.Shape
Dim subshp As Visio.Shape
Dim imgshp As Visio.Shape
Dim flagExists As Boolean
Dim cel As Visio.Cell
Dim celPrecedent As Visio.Cell
Dim aryPrecedents() As Visio.Cell
Dim country As String
Dim aryCountries() As String
Dim aryCodes() As String
Dim mstFlag As Visio.Master
Dim code As String
Dim idx As Integer
Dim filePath As String
Dim flagShp As Visio.Shape
Dim shpWidth As Double
Dim shpHeight As Double
Dim shpAspectRatio As Double
Dim flagWidth As Double
Dim flagHeight As Double
Dim flagAspectRatio As Double
Dim cloneShp As Visio.Shape
Dim cloneMst As Visio.Master

On Error Resume Next
    Set mstFlag = ThisDocument.Masters("Flags Of The World")
    If mstFlag Is Nothing Then
        Exit Sub
    Else
        aryCountries = Split(mstFlag.Shapes(1).Cells("Prop.Country.Format").ResultStr(""), ";")
        aryCodes = Split(mstFlag.Shapes(1).Cells("User.Fips10").ResultStr(""), ";")
    End If
    'Need a temporary writeable file need
    'You may need to change this but it needs to be gif extension

    filePath = Replace(Replace(ThisDocument.FullName, ".vss", ".gif"), ".vsd", ".gif")
    'Get the current shape(s)
    For Each shp In Visio.ActiveWindow.Selection
        If Not shp.DataGraphic Is Nothing Then
            For Each subshp In shp.Shapes
                If subshp.CellExists("User.msvCalloutType", Visio.visExistsAnywhere) <> 0 Then
                    If subshp.Cells("User.msvCalloutType").ResultStr("") = "Icon Set" Then
                        'We know that this shape is an Icon Set
                        If subshp.Name = "FlagPlaceholder" Then
                            'We know that the FlagPceholder exists
                            'Get the shape aspect ratio

                            shpWidth = subshp.Cells("Width").ResultIU
                            shpHeight = subshp.Cells("Height").ResultIU
                            shpAspectRatio = shpWidth / shpHeight
                            For Each imgshp In subshp.Shapes
                                If imgshp.Name = "Flag" Then
                                    'Found the Flag shape
                                    Set cel = subshp.Cells("User.msvCalloutIconNumber")
                                    If UBound(cel.Precedents) = 1 Then
                                        'Get the value in the precedent cell
                                        aryPrecedents() = cel.Precedents
                                        Set celPrecedent = aryPrecedents(1)
                                        country = celPrecedent.ResultStr("")
                                        idx = getLookup(country, aryCountries)
                                       If idx > -1 Then
                                            'We found a match for the country name
                                            code = aryCodes(idx)
                                            If Len(Dir(filePath)) > 0 Then
                                                'Clear the temp file
                                                Kill filePath
                                            End If
                                            Set cloneShp = mstFlag.Shapes(1).Duplicate
                                            cloneShp.Cells("Prop.Country").FormulaU = "=""" & country & """"
                                            cloneShp.Shapes(code).Export filePath
                                            cloneShp.Delete
                                            If Len(Dir(filePath)) > 0 Then
                                                'Remove the previous flag
                                                'Temporarily unlock the group

                                                subshp.Cells("LockGroup").FormulaU = 0
                                                imgshp.Delete
                                                Set flagShp = subshp.Import(filePath)
                                                flagShp.NameU = "Flag"
                                                flagShp.Name = "Flag"
                                                'Get the flag aspect ratio
                                                flagWidth = flagShp.Cells("Width").ResultIU
                                                flagHeight = flagShp.Cells("Height").ResultIU
                                                flagAspectRatio = flagWidth / flagHeight
                                                If shpAspectRatio > flagAspectRatio Then
                                                    'Maximise height of flag
                                                    flagShp.Cells("Height").FormulaU = "=" & shp.NameID & "!Height"
                                                    flagShp.Cells("Width").FormulaU = "=Height * " & flagAspectRatio
                                                Else
                                                    'Maximise width of flag
                                                    flagShp.Cells("Width").FormulaU = "=" & subshp.NameID & "!Width"
                                                    flagShp.Cells("Height").FormulaU = "=Width / " & flagAspectRatio
                                                End If
                                                flagShp.Cells("PinY").FormulaU = "=" & subshp.NameID & "!Height*0.5"
                                                flagShp.Cells("PinX").FormulaU = "=" & subshp.NameID & "!Width*0.5"
                                                'Reset the group lock
                                                subshp.Cells("LockGroup").FormulaU = 1
                                                If Len(Dir(filePath)) > 0 Then
                                                    'Clear the temp file
                                                    Kill filePath
                                                End If
                                            End If
                                        End If
                                    End If

                                    flagExists = True
                                    Exit For
                                End If
                            Next
                        End If
                    End If
                End If

                If flagExists = True Then
                    'Move on to the next shape in the selection
                    Exit For
                End If

            Next subshp
        End If
    Next shp
End Sub

Private Function getLookup(ByVal value As String, ByVal aryIn As Variant) As Integer
Dim ary() As String
    ary() = aryIn
Dim i As Integer
Dim found As Boolean
    For i = 0 To UBound(ary)
        If UCase(value) = UCase(ary(i)) Then
            found = True
            Exit For
        End If
    Next

    If found = True Then
        getLookup = i
    Else
        getLookup = -1
    End If
End Function

Note : The following web site was invaluable for helping me download the flag image files from the CIA web-site : http://www.vb-helper.com/howto_download_url_to_file.html

Interesting related blog: http://dbwhisperer.blogspot.com/2008/07/getting-geography-data-from-visio.html

Download files : http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/FlagsOfTheWorld.zip

June 19

Enhancing Visio Data Graphics Text Callouts

Visio 2007 Professional introduced the wonderful Data Graphics feature to display Shape Data in a clear visual way, but it is not clear how you may, for example, change the font of even the simplest Graphic Item type, Text Callouts.  In this blog, I’ll show you one method that I employ to vary the appearance of Text Callouts.  The same technique can be used for other Graphic Item types, Icon Sets and Data Bars.

I am using the  the sample IT Asset Management drawing to demonstrate throughout, which can be found in the Samples Template Category.  In this diagram, the server shapes on the topology page use the Topology 1 Data Graphic, which can be seen in the Data Graphics panel.

image

Microsoft had to introduce a new capability in Visio 2007 in order to get Data Graphics working, namely the ability for a shape instance to hold a reference to a DataGraphic master in addition to its normal master.  So, if you open the Drawing Explorer window, you can see the normal Server master, in addition to the Topology 1 Data Graphic master.  If you open the Topology 1 master, you can see the full Data Graphic, and you can expand the Master Explorer to show that there are multiple shapes inside it.  These shapes are the ones that you see displayed in a more friendly way in the Edit Data Graphic dialog.

image

However, you may also notice that this particular Data Graphic uses the same Text callout Graphic Item multiple times.  This is evident if you select Edit Item for Operating System, CPU (MHz), Memory (MB) or IP Address Data Fields in the Edit Data Graphic dialog.  In fact, you can only tell which Graphic Item master is being used in the Data Graphic master in code, or by opening the ShapeSheet of each of the sub-shapes.

image

You can see on the Edit Text dialog that you can edit certain properties, but font is not one of them!  SO, how can you edit the font?  Well, you could go around each shape in the diagram, sub-select the shapes and change it that way, or you can create a variation of the Text callout Graphic Item master.

In the Drawing Explorer window, select the Text callout master, then Duplicate on its right mouse menu.  You can then rename the new Text callout.xxx as whatever you like (I have used Text callout A).

image     image

Once you have a copy, you can double-click (or use select Edit Master Shape from its right mouse menu).  You will see that the Text callout master is comprised of two shapes, Sheet.5 (which is the group) and Sheet.6 (a sub-shape of the  group).  The Label text is part of Sheet.5, whilst the value (Abc) is part of Sheet.6.

image 

You can now edit the font of either the whole lot by selecting the shape, or you can just do the value by selecting Sheet.6 in the Master Explorer window.

  image

Now, you can close the Master Edit window to save the changes.

Now, when you go to the Edit Data Graphic dialog for Toplogy 1 Data Graphic, and select Edit Item for, say, Operating System, you will find your new variation, Text callout A, listed.

image

So, when you select your new variation of Text callout, all of the shapes that use it will be updated automatically!

image

Q.E.D.

By the way, there’s more like this in my book …

May 25

Visio FMPrint Add-on

A recent newsgroup post asked about accessing a network printers management page from a Visio page, so I thought I would share some things that I discovered a while back.  Visio 2003 and Visio 2007 Professional edition include an add-on called FMPrint, which you can use with any shape in Visio.  I used it with some network printer shapes in a couple of add-ins myself. I'm not aware of any public documentation about this handy little add-on, so here is what I have discovered.

You can see the add-on in action by opening the Shapes \ Maps and Floor Plans \ Building Plan \ Resources stencil and dropping the Printer shape onto your page.  Alternativaly you can start a new Maps and Floor Plans \ Space Plan drawing. Notice the SmartTag in the bottom left corner which gives you access to the FMPrint add-on:

image

If you open the ShapeSheet, then you will see that there are three Shape Data rows; four Actions; and 1 SmartTag associated with the add-on.

image

Shape Data Rows

Name Label Value
visPrinterModel Printer Model Enter manually or returned by "Find printer ..."
visPrinterLocation Printer Location Enter manually or returned by "Find printer ..." or "Browse ..."
visPrinterPath Printer Path Enter manually or returned by "Find printer ..." or "Browse ..."

 

Actions

Name Action Label Tag Name Button Face Disabled
visPrinter1 =RUNADDONWARGS("FMPrint","/cmd=3") "Set as &Default Printer" "PRN" "1100" =IF(LEN(Prop.visPrinterPath)>0,FALSE,TRUE)
visPrinter2 =RUNADDONWARGS("FMPrint","/cmd=4") "&Open print queue" "PRN" "986" =IF(LEN(Prop.visPrinterPath)>0,FALSE,TRUE)
visPrinter3 =RUNADDONWARGS("FMPrint","/cmd=2") "&Find a printer in the directory..." "PRN" "6371"  
visPrinter4 .=RUNADDONWARGS("FMPrint","/cmd=1") "&Browse for a printer..." "PRN" "1745"  

 

SmartTag

The visPrintern Actions appear under the SmartTag because they have the same TagName value.

Name Tag Name Description
visPrinter "PRN" =IF(Actions.visPrinter1.Disabled,"Configure Printer",Prop.visPrinterModel)

Find a printer in the directory

This enables you to search your Active Directory to locate a specific printer...

image

When you select one, then the Printer Model, Location and Path values are automatically filled in.

image

Open print queue

Once you have a value for the Printer Path Shape Data (which can be manually entered or automatically filled in from Find or Browse functions), then you are able to open the printer queue...

image

This will give you access to the printer's properties...

image image

Set as Default Printer

This function does give you the ability to set the selected printer as the default, but you may get a security warning....

image

Browse for printer

I have never managed to get this to return the Printer Model, and sometimes it just seems to hang, so I recommend either using Find or manually enter the values.

image 

Well, that's all I know about the FMPrint add-on ... does anyone know more?

April 24

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

April 21

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!

April 20

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

April 08

UK User Groups IT Pro Community Event

In my quest to promote Visio 2007 Professional as the visual information system of choice, I am presenting at the IT Pro Community event for the next two days, so I have posted my slides here. (Day 1 has little code, but Day 2 has lots of VBA code examples.):

http://www.ukusergroups.co.uk/index.html

Day 1 - Visualizing Information with Microsoft Visio 2007 slides:

http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/Visio%202007%20visualising%20data.pptx

Visio is a unique data visualization application, and the 2007 edition adds three new important data features that provide brand new data links, data graphics and pivot diagrams. These capabilities, along with the existing and often under-exploited tools, firmly position Visio as the foremost practical, easy to use visual information system that can be applied to a multitude of business scenarios. Microsoft Visio has been able to link ODBC data sources for many years via the Database Wizard, but this has limitations such as only a single data link per shape, and no support for stored procedures. Microsoft Visio 2007 overcomes both of these with the new Link Data programmable API, making it simple for end users and developers to create data rich diagrams that can be refreshed simply. In addition, the new Data Graphic features enable you to enhance linked shapes with icons, data bars, text callouts and color by value. The new Pivot Diagrams can be linked to data sources, including SQL Server Analysis Services, to provide interactive drill-downs of data diagrams, allowing the user to visualise, analyse, and present aggregate information in a new appealing manner. I'll demonstrate the new features...and show how these data links can be made.

 

Day 2 - Visualizing Information the Smart (Diagram) Way slides:

http://cid-3350d61bc93733a9.skydrive.live.com/self.aspx/Blogs/Visualising%20info%20the%20smart%20diagram%20way.pptx

Visio is a smart drawing tool, but it is even smarter when linked to corporate data, systems or processes, enabling it to be automatically refreshed to visualize the latest facts and figures. Data-linked Visio diagrams can be used for visualization of complex information; analysis of statistics; and communication to a broader audience with the Visio Viewer or as web pages.
This session will demonstrate linking Visio shapes to data from a variety of sources, including SQL Server stored procedures and XML files; how to drill-down into information using PivotDiagrams; and how to display data values with Data Graphics (and how to create your own). It will also include methods to automatically connect shapes together from data to create an Organization Chart without the Org Chart