I recently re-discovered an issue with callouts in Visio for a couple of projects that I am working on, and so I had to find a fix. The problem is that the callouts become dis-associated from their target shapes if either the layer visibility of the callout or the target shape is toggled off, and then back on again. This will result in a diagram with shapes without any connected callouts, so moving any of the target shapes will not move their associated callouts with them! I initially came up with a workaround that involved some jiggery-pokery with sub-shapes and layers, but it seems that the problem could have easily been averted if Microsoft had incorporated one specific User-defined Cell from the very start…
First, I should be clear which callouts I am talking about because the word has been used and abused over the years … This article refers to the callouts that are inserted from the Insert / Diagram Parts ribbon group. These are part of the Structured Diagrams concept that was introduced with Visio 2010.
I told the Visio development team about my findings and they trawled through the documentation that was originally created before the code base was passed from USA to India, and found this blog post. In short, there is an optional User.msvSDMembersOnHiddenLayer row, and, if it has a value, and if the value has a value of True then this disassociation would not happen at all.
Therefore I wrote a macro, FixCallouts(), to add this missing setting to any callout shapes in a document. This needs to re-run if any different types of callouts are added. I also discovered that there are two other requirements because of recent changes to Visio to add accessibility:
- Save the Visio document and re-open it to ensure that Visio heals inheritance of the User-defined Cells section because the Visio interface adds a row called visNavOrder to the shape instances
- Add the visNavOrder row to the master shape BEFORE adding msvSDMembersOnHiddenLayer
Note that the User-defined Cells section rows with black values are inherited from the master shape.
This is the code for the macro, with error trapping removed for brevity:
Public Sub FixCallouts() Dim mst As Visio.Master Dim shpMst As Visio.Shape Dim shp As Visio.Shape Dim mstCopy As Visio.Master Dim sect As Integer Dim row As Integer sect = Visio.VisSectionIndices.visSectionUser 'Loop through the Masters For Each mst In ActiveDocument.Masters Set shpMst = mst.Shapes(1) 'Check if structured (.IsCallout does not work in a master) If shpMst.CellExistsU("User.msvStructureType", _ Visio.VisExistsFlags.visExistsAnywhere) <> 0 Then 'Check if a Callout shape If shpMst.CellsU("User.msvStructureType").ResultStr("") = _ "Callout" Then If shpMst.CellExistsU("User.msvSDMembersOnHiddenLayer", _ Visio.VisExistsFlags.visExistsAnywhere) = 0 Then 'Open the master to edit it Set mstCopy = mst.Open Set shp = mstCopy.Shapes(1) 'May need to add User.visNavOrder first! If shpMst.CellExistsU("User.visNavOrder", _ Visio.VisExistsFlags.visExistsAnywhere) = 0 Then row = shp.AddNamedRow(sect, "visNavOrder", 0) End If 'Then add User.msvSDMembersOnHiddenLayer row = shp.AddNamedRow(sect, _ "msvSDMembersOnHiddenLayer", 0) shp.CellsU("User.msvSDMembersOnHiddenLayer").FormulaU = "=TRUE" 'Closing saves the changes mstCopy.Close 'Set the Match Master by Name on Drop to True to avoid duplicates mst.MatchByName = 1 End If End If End If Next mst End Sub
So, after running this macro an existing Visio document that contains callouts, the layers of either the callouts or the target shapes can be toggled without breaking the associations!
The macro can be downloaded from here. Simply save the macro-enabled stencil, FixCalloutsIssue.vssm, in your My Shapes folder, and open it within Visio when required. The macro can be run from View / Macros …