• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Visio Guy

Smart graphics for visual people




  • Home
  • Hire Me
    • Hire Me
    • Résumé
  • Products
    • Products
    • Bubble Revision Shape
    • Layers to Pages Utility
    • Rack Unit Dimension Line
    • Radial Elements Tool with up to 100 Wedges
    • Text on a Circle Visio SmartShape
  • Index
    • Articles by Date
    • YouTube – VisioGuy
    • Download Information
    • Suggestion Box
    • Shop
    • Visio Art
    • Visio Links
    • – Visio Shapes & Stencils
    • – Visio Templates & Drawings
  • About
    • About
    • Donate
    • GitHub
    • jsFiddle
    • Reading List
    • Subscribe & Follow
      • – E-mail
      • – facebook
      • – Twitter
      • – RSS
    • Privacy Policy
  • Discussion Forum
You are here: Home / Development / Code / Send All Connectors to Back

Send All Connectors to Back

June 17, 2009 By Visio Guy 3 Comments

i-want-you-connectorI Want You, Dynamic connector!

When I’m creating Visio-based graphical solutions, I frequently run into the situation where I want to send all of the connectors on a page to the back.

There are a number of reasons to do this, but more importantly for Visio Guy readers, there are a number of ways to do this!

In today’s article, you’ll learn a number of methods to select shapes by type or layer, and you’ll see a little bit of VBA code that will help you automate the task!

In order to send all of the connectors on a page to back, we need to create a Selection of connector shapes. Once we have a selection of shapes, we can quickly call the Send to Back command on them.

So this article is really about how to select specific groups of shapes.

For End-users: The Select by Type Feature

If you have a complicated drawing, selecting a sub-set of shapes on a page can be an excercise in Shift+Click misery.

But if you’ve ever peeked closely at the Edit menu,  you may have noticed the Select by Type item:

select-by-type-menu

Once you click this item, you’ll be presented with this nifty dialog:

select-by-type-dialog

You can see that shapes can be selected by Layer, which can save you a LOT of time. Here we can see that we can select shapes on the Connector layer in one fell swoop.

We can also select shapes that aren’t on a layer at all. This might be useful for drawings that insist that all objects be on a layer. You could quickly check if any shapes had slipped through the cracks!

Unfortunately, there is no select shape by Master, which would also be extremely useful. The select by Shape type seems to lead us in that direction, but alas, there is no Master check box. FEATURE REQUEST FOR MICROSOFT: Add Select by Master to the Select by Type dialog!

Select by Layer  Code

Analogouse to the Select by Type – Layer option we saw above, you can programmatically select shapes by layer.  As you might have guessed from that dialog, Visio’s built-in, Dynamic connector comes pre-assigned to the Connector layer, so we can take advantage of this in our code.

Below, our code snippet defines a Layer object that corresponds to the Connector layer. Once we have this object, we can ask Visio to return a selection of shapes on that particular layer.

And once we have a Selection of shapes, we can call SendToBack to put them behind all other shapes on the page.

Note, you’ll want to check that a layer exists in your own code, but we’ve kept the sample as simple as possible for clarity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sub SendConnectorsToBack_ByLayer()
 
    '// Get the active page:
    Dim pg As Visio.Page
    Set pg = Visio.ActivePage
 
    '// Get the connectors layer:
    '// Note, ItemU should work for non-English Visio
    Dim lyr As Visio.Layer
    Set lyr = pg.Layers.ItemU("Connector")
 
    '// Get a selection of connectors, by layer:
    Dim sel As Visio.Selection
    Set sel = pg.CreateSelection( _
    visSelTypeByLayer, visSelModeSkipSub, lyr)
 
    '// Send the selection to back:
    If (sel.Count > 0) Then
        Call sel.SendToBack
    End If
 
End Sub
Sub SendConnectorsToBack_ByLayer()

    '// Get the active page:
    Dim pg As Visio.Page
    Set pg = Visio.ActivePage

    '// Get the connectors layer:
    '// Note, ItemU should work for non-English Visio
    Dim lyr As Visio.Layer
    Set lyr = pg.Layers.ItemU("Connector")

    '// Get a selection of connectors, by layer:
    Dim sel As Visio.Selection
    Set sel = pg.CreateSelection( _
    visSelTypeByLayer, visSelModeSkipSub, lyr)

    '// Send the selection to back:
    If (sel.Count > 0) Then
        Call sel.SendToBack
    End If

End Sub

 

Select by Master Code

While the Select by Type dialog didn’t offer the ability to select by Master, Visio’s automation model does! This code looks almost identical to the previous select-by-layer procedure, except that a Master object is passed to the page’s CreateSelection method, instead of a Layer object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sub SendConnectorsToBack_ByMaster()
 
    '// Get the active page:
    Dim pg As Visio.Page
    Set pg = Visio.ActivePage
 
    '// Get the connector master:
    '// Note, ItemU should work for non-English Visio.
    Dim mst As Visio.Master
    Set mst = pg.Document.Masters.ItemU("Dynamic connector")
 
    '// Get a selection of connectors, by layer:
    Dim sel As Visio.Selection
    Set sel = pg.CreateSelection( _
    visSelTypeByMaster, visSelModeSkipSub, mst)
 
    '// Send the selection to back:
    If (sel.Count > 0) Then
        Call sel.SendToBack
    End If
 
End Sub
Sub SendConnectorsToBack_ByMaster()

    '// Get the active page:
    Dim pg As Visio.Page
    Set pg = Visio.ActivePage

    '// Get the connector master:
    '// Note, ItemU should work for non-English Visio.
    Dim mst As Visio.Master
    Set mst = pg.Document.Masters.ItemU("Dynamic connector")

    '// Get a selection of connectors, by layer:
    Dim sel As Visio.Selection
    Set sel = pg.CreateSelection( _
    visSelTypeByMaster, visSelModeSkipSub, mst)

    '// Send the selection to back:
    If (sel.Count > 0) Then
        Call sel.SendToBack
    End If

End Sub

Why Send Connectors to Back?

Ok, the “select special” stuff was cool enough, but you still might be wondering why I would ever waste my time sending connectors to back?

I can think of two cases right off the top of my head, so I’ll share them quickly before you get back to work.

Sometimes it is convenient to connect shapes center-to-center. But if your connectors are on top, your diagram won’t look so hot. Sending connectors to back easily remedies the situation:

center-to-center-case

Another case involves line-weight. You may have connections that attach at shape edges, thus eliminating the previous problem.

But if your connectors are thicker than your shape-outlines, you will still get problems with the line-end cap. Sending connectors to back will fix this problem too!

thick-line-case

Of course, you can always call SendToBack each time you drop a connector on the page, or you could just be sure to drop the connectors before you drop the shapes.

But I’m sure that you’ll run into good reasons–such as performance or code-organization–to send them all to back with one, central procedure. And even if you never send a single connector to back, you’ll surely find use for the select-by-layer and select-by-master procedures we’ve talked about today!

  • Tweet
  • More
  • Pocket
  • Share on Tumblr
  • Print
  • Email

No related posts.

Filed Under: Code

Previous Post: « Rate (Your) Network Diagram
Next Post: User Experience Shapes From UserFocus »

Reader Interactions

Comments

  1. Stephanie says

    June 7, 2010 at 8:19 pm

    I inadvertedly did something to a graph and now my connects will not connect to the object. I don’t get a red box to save my soul. I have tried to copy and past, I have try starting over, but nothing will change it back. Very new to Visio and lack time to really study it. Any suggestions?

  2. Ahliana Byrd says

    July 22, 2010 at 12:29 am

    Thanks! This provided the very easiest and quickest way to do what I needed. My flowchart has become complex, and I kept accidentally hiding connector ends. This was the instant way to bring them to the front.

    THANKS!

  3. Martin says

    June 17, 2014 at 10:25 am

    Where is this Option at Visio2013?

Leave a Reply Cancel reply

Primary Sidebar

Buy Über Bubble Revision Shape
Purchase

Categories

Buy my book!

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tag Cloud

A/V Artistic Effects BPM Code Connectors Control Handles Countries Custom Patterns Custom Properties Data Graphics Data Linking Data Visualization David Edson David Parker Fill Format Formulas Functions Geometry Gradient Images Links Maps Multi-shapes Network Programming repeating shapes Resources Right-Click Actions Scale Shape Data ShapeSheet ShapeSheet Formulas ShapeSheet Functions SharePoint shiny SmartShapes Sport Sports Text Themes Tools Transparency User-defined Cells Visio 2007 Visio SmartShapes

Top Posts & Pages

  • - Visio Shapes & Stencils
  • - Visio Templates & Drawings
  • Amazon AWS Visio Shapes
  • Dynamic Updating Org Charts in Visio!
  • Text on a Circle Visio Shape
  • Bubble Revision Shapes
  • Crayon Visio Network Shapes, Revisited
  • Sankey Diagram Shapes for Visio
  • Map of World
  • AV Engineering Diagrams with Symbol Logic ECAV

www.visguy.com - Visio Guy - since 2006

 

Loading Comments...