What’s in Your Drawing?

This post will be a little experiment to try out file attachments on the blog.

When customers send files to us, we often want to get a general understanding about the drawing contents.  This is common in scenarios where customers are concerned about performance or file size.  Visio drawings may be carrying some excess baggage along.

In addition to shapes on the page, a Visio document contains information about master shapes, styles, layers, fonts, colors, data and other items.  These collections of information are used to accurately present the shapes on the page.  However, they do not automatically get purged when shapes are deleted from the diagram.

Take the simple example of a flowchart.  If you drag a Process shape onto the drawing page, Visio adds a copy of the Process master shape to the document and places an instance of this master shape on the page.  If you delete the Process shape from the page, the master shape remains.  Over time unused master shapes pile up.  Normally this is no big deal, but some shapes contain large bitmaps or other complex information that will quickly increase file size.

Before you go out and delete every master shape from your document, keep in mind that master shapes are highly efficient when they are actually used in the drawing.  If you took a drawing with many copies of the same shapes and then deleted the master, you would find the resulting document much larger and slower.

The attached DrawingAnalyzer.vsd document is a handy little tool written in VBA for counting the shapes in a drawing and determining whether there are unused master shapes.  Also the tool counts shapes on the page with no master shape, and it keeps track of the level of grouping among shapes.  More nested groups mean much slower performance.

To use the tool, open the file in Visio along with any other document you want to analyze.  Make sure the document to be analyzed is in the active window.  Then go to Tools > Macro > DrawingAnalyzer > ThisDocument > GetDrawingStats.  Then open the VBA Editor (Alt+F11) and look in the Immediate Window (Ctrl+G) at the output.  Here's a sample result:

Total Pages:             3
Total Shapes:            495

Top Level Shapes:        11
Group Shapes:            92
Max Nesting Depth:       3
Total Masters:           13
Unused Masters:          0
Shapes w/o Masters:      36
Total Patterns:          0
Unused Patterns:         0
Total Styles:            9

A top level shape is a shape directly on the page.  All other shapes are found inside of groups.  In this example, there are only 11 shapes spread across the 3 pages in the drawing.  However, the total number of shapes is 495, meaning there are lots of shapes inside groups.  There are even groups inside groups inside groups as evidenced by the maximum nesting depth of 3.  This is not terribly efficient.  All 13 master shapes in the document are used in the drawing, so that is good.  36 shapes have no master.  If any of these shapes are similar, it would be more efficient to create a master shape for them.

The DrawingAnalyzer.vsd file is saved in Visio 2000/2002 format.  Please post a comment if you have difficulties getting the file.  As we said, this is a test.




Comments (5)

  1. Michael Dag says:

    got the file perfectly!

    on the topic of masters… Is it possible to replace a shape’s master with a newer version?

    if yes, please provide a sample?

    another topic is document colors, as documents are copied and re-used a lot of the ‘custom’ colors keep growing in a document. Is there a way to clear the unused ‘custom’ colors from a document?

    thanks and I enjoy reading your frequent posts!

  2. Visio Team says:

    Good questions, Michael.  

    There is no built-in mechanism for replacing a shape’s master (if you want all the existing instances to switch over to the new master as well).  Shape replacement in general is a frequent newsgroup topic.  I’ll look into creating a simple shape replacement macro and use it to talk more about user expectations here.

    The best way to clear out document colors would be to save the drawing as XML (Visio’s .vdx extension) and edit the color table.

    Mark Nelson

  3. Michael Dag says:

    > I’ll look into creating a simple shape replacement macro and use it to talk more about user expectations here.

    That would be nice!

  4. Michael Dag says:

    > I’ll look into creating a simple shape replacement macro and use it to talk more about user expectations here.

    any update on the shape replacement macro?

  5. Tricia Wilcox Almas says:

    Thank you, thank you, thank you!  I have been struggling with a rather large data model in Visio, trying to figure out how many tables were represented!  This is a very useful tool!

Skip to main content