Fixing the layers problem with callouts in #Visio

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 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:

  1. 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
  2. Add the visNavOrder row to the master shape BEFORE adding msvSDMembersOnHiddenLayer

 

This slideshow requires JavaScript.

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

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Simplify Tasks

Want to learn the simple way?

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

John Goldsmith's visLog

be smart, be clear, be visual ...

Mo's blog

Personal views on Dynamics 365 for Operations and Technical Architecture.

Chris Webb's BI Blog

Microsoft Power BI, Analysis Services, MDX, DAX, M, Power Pivot and Power Query

davecra.wordpress.com/

Microsoft Office 365 Development, and more...

PowerShell.Amsterdam

Automate, Accelerate, Accurate

johnvisiomvp

Life with Visio and other Microsoft Toys!

Title (Required)

Windows Server Essentials Tips & Tricks

Nilsandrey's Weblog

Just another WordPress.com weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Smart graphics for visual people

Pluralsight blog

be smart, be clear, be visual ...

%d bloggers like this: