Most of my Visio diagrams have simple connections between shapes, and my previous post about connections used a flowchart as an example (see https://blog.bvisual.net/2016/08/09/understanding-visio-connections/ ). However, it has come to my attention that some Visio developers add connection points to sub-shapes of Visio group shapes, and then connect between the sub-shapes. This means that the code in my previous article would need to be adapted to cater for this scenario. It has also meant that I needed to update my free multiSelect Visio add-in needed an update. The updated version (184.108.40.206) is for Visio 2010+, and is available from http://bvisual.net/Products/multiSelect.aspx .
I have added in three more options into the multiSelect add-in that work with the Parent, Children and Siblings actions:
- Keep source selected – previously the actions dropped the original shape from the selection.
- Include sub-shapes – it can take longer to explore the sub-shapes of large shapes, so I made it optional
- Prefer sub-shapes – if connected to a sub-shape, then select the sub-shape rather than the parent group shape
There were a couple of challenges in adapting the code.
- Recognising that the connected shape was a sub-shape
- Selecting a sub-shape programmatically
I solved the first challenge by testing if the Connect.ToSheet.ContainingShape.ID equals 0 for the end of a connector. If it is, then the shape it is connected to has the page as a parent; if not, then the ID is the parent shape, which can be retrieved using Page.Shapes.ItemFromID(…).
The second challenges was surprisingly more difficult. The Window.Select(…) method has an argument for the type of selection. The trick is to select the group shape first using visSelectArgs.visSelect, and then to immediately select the sub-shape using visSelectArgs.visSubSelect.