• 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 / Automatically Number & Connect Shapes – With Code!

Automatically Number & Connect Shapes – With Code!

July 13, 2009 By Visio Guy 9 Comments

connected-bubblesDo you need to number shapes automatically? Do you need to connect shapes in the order that they are numbered?

If you are developing an automated, graphical solution on top of Visio, you might face these requirements. This article and accompanying download will help you to meet them.

Or if you just want tools for step-numbering and ordered connecting, you might be able to modify and extend the VBA code contained in today’s download to help you get the job done.

Fellow Microsoft MVP Dave Edson sent me another example of how you can programmatically deal with Visio shapes and the connections between them. Dave’s demos are regularly polished and “ready to ship”, but in today’s case, I couldn’t help tweaking and adding features.  So today’s article is a joint effort, but it is Dave’s fault:)

Connect Numbered Visio Shapes in Order

The point of the demo is to connect shapes in the order that they are numbered. The Visio document in the download at the end of the article contains a special Step Bubble master shape that has a Shape Data field called Step Number. Step Number is the index that you need to change in order to set the order of the shapes.

Once you’ve got shapes on the page, the code will analyze the shapes’ step numbers, then connect the shapes in the proper order.

Dave did the shape and connection code, and I added a button to automatically place and number shapes, another one to connect them, and some visual aids to the shapes to help you see (and check) that the code did the job correctly.

These ease-of-use features allow you to set up the demo-environment more quickly, but are no excuse for not digging into the ShapeSheet behind the Step Bubble, or looking into the VBA code stored in the document.

Adding Numbered Shapes

First we need shapes with indices, otherwise there will be nothing to connect!

If you manually drag a Step Bubble master from the Document Stencil into the drawing page, you will be presented with a pop-up dialog that allows you to set the Step Number for the shape:

shape-bubble-with-step-number

click to view larger image

The connect code will then try to follow your shapes in order of their step numbers. But if you don’t feel like individually numbering all of your shapes, just click the button at the bottom-left of the page.

When you click the 1. Add Step Bubbles button, the VBA code stored in the document will automatically drop a step shape onto a random spot on the page, and set the shape with the next available step number, automatically!

Note: The drawing contains VBA (Visual Basic for Applications) code that your Visio security settings may prevent from running. If you are not familiar with VBA macros, please read:  VBA Macro Security. It will help you to understand in-document macros, related security issues, and how to allow them to run when they come from trusted sources.

Connecting the Shapes

Now that your page is full of numbered, just click the second button: 2. Connect Step Bubbles.

Your shapes will be connected in the order of their Step Number properties. I’ve added numbers to the connectors, so you can see which were drawn first, which were drawn last. Also, the connectors have different line ends to show direction: white circle at the beginning, double-black arrowhead at the end.

connect-shapes-in-order-visio

click to view larger image

Digging In to the Code

The quickest way into a Visio document’s VBA project is via: Alt + F11. Once you’re there, I thought I’d point out some of the more interesting procedures to help guide your exploration:

  • ThisDocument.Button_AddSteps_Click
    This is the code behind button #1 – it calls the other subroutines that drop step shapes, set step numbers, and add random text. It looks at existing step bubbles and notes existing step numbers so as not to create a duplicate. It also selects a random location to drop the new step, such that it is on the page, but not on top of the buttons.
  • ThisDocument.Button_ConnectSteps_Click
    This is the code behind button #2. It deletes all of the existing connectors on the page, then it connects the step bubbles in order.
  • ThisDocument.m_deleteAllConnecors
    This is the low-level sub that actually deletes all of the connectors. It selects all “Step Connector” masters, then deletes them. Worth a look if you need to select or delete shapes of a particular type.
  • ThisDocument.m_getRandomText
    Picks a random foreign word for bubble. If you are relatively new to VBA programming, this might be interesting for you to look at.
  • ThisDocument.m_getUniqueStepNumber
    This picks a new, ordered, unique step number for the “next” step shape that lands on the page. It “fills in gaps” in that if a step number is missing, ie: 1, 2, 3, 5, it will pick the lowest missing step number first. “4” in this example.
  • ConnectCode.ConnectTheDots
    This where the order-searching is done, and the shapes are connected. Note that if a step is missing, no connector is drawn.

Download “Connect Shapes in Order.zip” s!Aj0wJuswNyXlhnS_ET8SY_T9Vbap – Downloaded 4970 times – 103 B

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

Related posts:

  1. Analyze Connectivity Between Process Flows

Filed Under: Code, Video Tagged With: Connectors, David Edson, Pr

Previous Post: « Top Visio Guy Posts
Next Post: Visio Services and SharePoint 2010 »

Reader Interactions

Comments

  1. John Distai says

    July 13, 2009 at 5:15 pm

    Thank you so much for publishing this! I have a need to do something similar, but didn’t have a clue on how to do it. This will be so helpful!

    JD

  2. Attila Osztrogonacz says

    July 14, 2009 at 12:44 pm

    Thanks a lot for this. This feature wil be incorporated to the next version of our work.

  3. John Distai says

    July 22, 2009 at 5:59 pm

    Thanks for providing this. I am trying to look at the code, and when I click Alt-F11 all I see is the connect the dots portion of the code. How do I see the other “ThisDocument” related code?

    Thanks!

  4. Visio Guy says

    July 22, 2009 at 10:31 pm

    Hi John,

    The VBA project can have all sorts of classes, modules and forms. This one has two code “files” or code blobs.

    You need to see the project explorer to be able to get at all of the code modules. This is available under: View > Project Explorer

  5. firas says

    August 13, 2009 at 9:08 pm

    dear Visio Guy
    i have 10 shape and i want to chose from them to put on top of each other ,it is not always the 10 shape so i want to position the shapes in the middle automatically and i want the software to resizing them depend on the amount of shape and i want him to show me the length of each shape (will will have it in data base or exel)and i want from software to show the distance from the bottom shape to each shape

    is it possible to be made

  6. Marque says

    August 29, 2009 at 7:53 am

    Many thanks indeed. Begs the question as to why this sort of functionality is not already in the product as it so very very useful?
    Well done chaps! This site has allowed me to learn/use visio that bit more. Many thanks.
    Marque

  7. Nny says

    December 12, 2013 at 8:52 pm

    Thanks a lot for this code !
    Very usefull.

  8. Dan says

    October 13, 2014 at 1:29 pm

    This is close to what I was looking for but is there a way for the connector shape properties to take on the “where from” connection point and the “where to” connection point? I would like to tie the data from all of these to an MS Access database.

Trackbacks

  1. Visio Guy » Top Visio Guy Downloads (as of November 2009) says:
    November 17, 2009 at 10:28 pm

    […] (56.7 downloads/month, 3.8 months) Connect Shapes in Order […]

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 BPMN 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 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
  • Bubble Revision Shapes
  • Go 3D with Free Isometric Piping Shapes for Visio
  • Map of World
  • Visio Network Server Shape Icon Customization Tool
  • Dynamic Updating Org Charts in Visio!
  • Sankey Diagram Shapes for Visio
  • Amazon AWS Visio Shapes
  • Visio Circle Arrows 2013

www.visguy.com - Visio Guy - since 2006

 

Loading Comments...
 

    loading Cancel
    Post was not sent - check your email addresses!
    Email check failed, please try again
    Sorry, your blog cannot share posts by email.