Freigeben über


Dev Luv: Editing Visio Masters

The shapes that you see on the stencil on the left pane of Visio are called “masters.” Think of a master as an object. When you drag a master from the stencil, you are dropping an instance of that master object onto the page. That instance, which we call a Visio shape, inherits its geometry and behaviors from its master.

 

Right-click on a shape in a Visio stencil and you’ll see lots of grayed options in the right-click menu. The stencil is read-only, which means you can’t modify the masters. Right-click on the title bar of any stencil, though, and you can save the stencil under another name, which turns the document read/write. You can then right-click on the master and choose Edit Master to modify the geometry and/of behaviors. When you do that, you get a dialog that tells you that in order to save the changes to the master, you need to close the window and save the drawing. This behavior demonstrates something that you need to know about masters if you plan to programmatically update them: masters follow a commit model. If you don’t work with the master commit model, you may get unexpected behavior when programmatically modifying masters.

 

You can modify a master using the Master.Open method. The Open method opens a copy of the master. (Once you’re done working with this copy, make sure to explicitly release it in non-VB programs.) Once you make changes to the master copy, you need to call the Master.Close method to commit the changes to the master object. If Master.Close is called on a master that hasn’t specifically been opened using the Master.Open method, the Close method fails. If the Close method succeeds, the changes that you made to the master copy get merged back into the master object and all instances of that Master in your code are updated with the changes.

 

This is an important concept when working with masters because it can be hard to figure out why your changes to masters aren’t sticking. Any changes to cells and shapes for masters need to be made using Master.Open and Master.Close to persist the changes to your master object and its instances.

 

-- Mai-lan

Comments

  • Anonymous
    March 25, 2005
    Mai-lan,
    let's say I have a stencil with master A and a drawing that has 3 instances of master A in it.
    If I want to add an additional custom property to Master A and it's instances in the drawing, I could open the Master, add the property, Close the Master and the 3 instances in the drawing will get the property automatically?

    What happens if this stencil is used in other drawings as well, will they get updated as well?

    Up until now I have manually added custom properties and then ran some code on all drawings to update the individual impacted shapes.

    if what I am doing is not neccessary I would love to see a working sample!