Remove extra shapes from Master Document Stencil

S

Smerchek

When you drop a shape from the Visio stencils onto a page, a copy of that
master is added to the Document Stencil. When the shape is deleted from a
page it is not removed from the Document Stencil. By cleaning out the
Document Stencil of unused Master Shapes you can decrease the size of your
saved drawing files.

I have included the VBA code from a macro that I created to clean up unused
shapes from the Document Stencil.



' Loop through each master then check across pages to see if it is used
index = vsoDocument.Masters.count
While index > 0
bMasterUsed = False
Set oMaster = vsoDocument.Masters.Item(index)

For Each oPage In vsoDocument.Pages
For Each oShape In oPage.Shapes
If oMaster.Name = oShape.Name Then
bMasterUsed = True
End If
Next
Next

' if Not used delete it from the document stencil
If bMasterUsed = False Then
oMaster.Delete
End If
index = index - 1
Wend
 
M

Mark Nelson [MS]

This is a great way to reduce file size and clean up your document. One
thing to consider is that some masters probably should be left in the
document even if they are not in use at the moment. The most common example
is "Dynamic Connector" since this is the master that defines what the
Connector Tool will draw. Another example is the set of masters used in
Organization Charts, since that solution expects the masters to be present.

We've added a document clean up feature to Visio 2007 called Remove Hidden
Information. This allows users to remove unused masters and styles among
other things.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris Roth [MVP]

A few things to add:

1. When looping through shapes, you need to recurse through all groups,
because several masters might be grouped together, and thus hidden from
Mark's example.

2. If you save the file as .vsx, in Visio xml format, you can do the
cleaning using Xml technologies - DOM and what not. You'll find that the
master cleaning process by this method runs about a billion times faster : )


--
Hope this helps,

Chris Roth
Visio MVP

www.wanderkind.com/visio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top