Improving Vendor-Provided Visio Stencils that are Less than Great

As an IT professional, I’ve had occasion to use Microsoft Visio perhaps two or three thousand times. Given that it has been the de facto standard in creating visual representations of complex architectures and other technological concepts for close to two decades, it’s likely you’ve encountered the tool yourself.

Generally speaking, it’s all well and good to open the application, choose applicable stencils for your project (bundled or those you’ve downloaded from a third party), and start dragging shapes onto the page. A few labels and some strategically placed lines, and you’ve got yourself a passable diagram ready to share with your colleagues… yay. There are sometimes, however, when one of these third parties make available a well-intended, but ultimately awful, set of stencils that they invite you to use to document their nifty widgets and doodads… thus was my experience recently when I downloaded Amazon’s AWS Visio stencils, and this blog post details what I did about it.

Why the Provided Stencils are Less than Great

This isn’t the first time I’ve dealt with subpar third party Visio stencils, but it was definitely the first time that I found the experience so viscerally frustrating as to force me to figure out how to fix them — or, at the very least, make them somewhat less terrible. If you’ve tried using these AWS stencils, you probably noticed issues-a-plenty:

  1. Seemingly random shape sizes and nonsensical proportions within and across stencils;
  2. Annoying and superfluous text embedded in the shapes;
  3. No use of shape data for capturing shape details;
  4. No handles for positioning label text.

In short, these things are a mess. While the first three are things that one must remediate by hand (or, at least, they are things that I remediated by hand because, perhaps, I’m simply not smart enough to figure out how to automate them), after some considerable trial and error — a fair amount of emphasis on the latter — I was able to craft a VBA macro that placed a text handle in a consistent location allowing me to appropriately label these buggery shapes in a not nonsensical place (such as superimposed over the shape itself): 

Now, I’ve been accused of being pedantic once or craft VBA macro to place text handle in consistent location with appropriate label in Visio stencil by Jason Ramsey at Easy Dynamicstwice, but I’ll wager that even the laziest of diagrammers will find the “After” shown right to be at least a little easier on the eyes and, you know, not entirely useless.

So, anyway… let’s get to the bit where I show you how to do the thing I did so you don’t have to spend the time doing what I did.

How To Improve the Provided Stencils

First, you need to make sure that you’ve got the Developer Tools for Visio installed and turned on. Without them, you can’t peek into the dark void that is ShapeSheets (the tabular attribute information that instructs Visio how to present visual data), and you can’t create your own VBA macros. Given that the method I’m going to give you to create text handles on the shapes is going to require you to write a VBA macro, you’re going to want that.

Next, if you don’t already have them, you’re going to want to grab the AWS Simple Icons. You have the option of grabbing Amazon’s [broken] stencils or choosing a number of other options that they have made available. Full disclosure: I started with the Visio stencils, but once I realized how not great they are, I grabbed the EPS/SVG zip file and imported them (the SVG versions since Visio natively supports that format) into Visio individually and rolled my own stencils from scratch. So, in addition to the code that I cobbled together (below) that adds text handles, I also performed the following steps for every shape in the stencil set:

  1. Import the shape’s SVG onto the drawing area
  2. Resize the shape to round measurements that work nicely on a grid while keeping shape sizes as consistent as possible and maintaining proportionality where it made sense
  3. Remove any superfluous text from the icons (seriously, aren’t the icons themselves supposed to tell you what a thing is!?)
  4. Run the macro (again, found below) to add a text handle
  5. Drag the custom shape into a custom stencil and change its name to something that makes sense

{{cta(‘209aad85-272d-4e83-8cdc-4f30262bc921′,’justifyleft’)}}I also made some other major changes such as adding shape data and custom labels to EC2 instance icons and making it so the indicator icons for container objects (Regions, VPCs, Subnets, Spot Fleets, etc.) don’t resize with the container frame — one of the “features” of the stock templates that I simply could not abide — since it would take me days and days to write a detailed how-to on each of these steps, I thought, instead, I would share the solution to the most frustrating issue I had: programmatically creating text handles on the shapes for labeling purposes.

The rest of it is something most Visio users can sort out by themselves, but I was unable to find a working solution to this problem online after many minutes of searching. Hopefully, the search results that perhaps led you here will prove to be more fruitful!

So anyway, go into Visio and click the “Developer” tab. If everything is installed that you need to have installed, you should see a button that says “Visual Basic.” Click on that. A Visual Basic for Applications window should open up in editor mode allowing you to write (or copy/paste) code for a macro that you can use (and reuse) within Visio. Here below is the code that I landed on. You’ll see that what I decided to do was to permit the selection of multiple shapes on the page and automatically create text handles below the shape:

Sub AddShapeControlHandle()

Dim vsoShape As Visio.Shape

For Each vsoShape In Visio.ActiveWindow.Selection
If Not vsoShape.SectionExists(visSectionControls, True) Then
vsoShape.AddSection visSectionControls
vsoShape.AddNamedRow visSectionControls, "visSSTXT", 0
End If

'Populate the Controls cells
vsoShape.Cells("Controls.visSSTXT.x").FormulaU = "Width*0.5"
vsoShape.Cells("Controls.visSSTXT.y").FormulaU = "-0.25 in"

If Not (vsoShape.RowExists(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisExistsFlags.visExistsAnywhere)) Then
Call vsoShape.AddRow(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisRowTags.visTagDefault)
End If

'Populate the Text Transform cells
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormWidth).FormulaU = "MIN(TEXTWIDTH(TheText),Width*2.5)"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormHeight).FormulaU = "TEXTHEIGHT(TheText,TxtWidth)"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinX).FormulaU = "Width*0.5"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinY).FormulaU = "SETATREF(Controls.visSSTXT.Y)"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinX).FormulaU = "TxtWidth*0.5"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinY).FormulaU = "TxtHeight*0.5"
vsoShape.CellsSRC(visSectionObject, visRowTextXForm, visXFormAngle).FormulaU = "IF(BITXOR(FlipX,FlipY),1,-1)*Angle"

Next vsoShape

End Sub

Closing the window when done editing is sufficient to Assigning appropriate macro to specific character for new Visio stenils by Jason Ramsey at Easy Dynamicssaving the code as part of the open file. Now that you have this handy-dandy code as a macro, you probably want to be able to execute it easily. I did this by assiging a shortcut key to the macro in Visio.

This is done by going to the Developer tab and clicking the Macros button. Once the Macros window opens, you can highlight the appropriate macro and click the “Options…” button. There you can specify a character that when pressed with the Ctrl key will execute your shiny new macro just like a native command.

Boom. Done. Finito. You have successfully fixed a broken shape and can use them effectively in your diagrams now.

The Wrap-Up

Visio is a terribly powerful tool that can be made terribly awful by third-party stencils that aren’t up to snuff. I’ve demonstrated how to fix one aspect of these shortcomings, but the really tedious work in this is taking all of the{{cta(‘8a9fb233-94e7-4220-901a-dc7f556ed529′,’justifyright’)}} shapes in all of the stencils provided by a third party, fixing them, and creating your own stencils.

Having done this, I honestly wouldn’t wish it on anyone else, so you can download the reworked AWS / Visio stencils and 2013/2016 templates that references them all that I created for my own use. I’m sure there’ll be some kind of contact information provided somehere on this page, but, failing that, I’ll track the comments and be happy to provide what I have to anyone that asks. I hope you’ve found this little write up in some way useful! 


What other ways have you fixed AWS-provided or third-party stencils in Visio? Share your wisdom with us in a comment below! 

While you’re here, make yourself comfortable and check out our blog home page to explore other technologies we use on a daily basis and the fixes we’ve solved in our day to day work. To make your life even easier, subscribe to our blog to get instant updates sent straight to your inbox:

{{cta(‘33985992-7ced-4ebd-b7c8-4fcb88ae3da4’)}}

Leave a Reply