Visio 2013 - Creating duplicate stencils with different colour schemes.

Started by rainfordr, March 22, 2017, 10:08:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rainfordr

Hello All,

I have several stencils which are basically the same, but with different colour schemes (You know the type of thing - a bunch of masters in each stencil of bikes and cars or whatever that are blue, or yellow, or green, etc. depending on which coloured stencil you have) and it's taking me quite a while to go through each one and change the colours. there are about 100 shapes in each stencil and each diagram may have multiple stencils. My colleagues may want to create different coloured stencils on top of the ones I have too.

What I'm after is some quick way to take a stencil, duplicate it and change one colour within each shape. I'm currently going through and manually changing the colour of each Master and it is taking forever.

I had thought about using a theme and changing one colour, but I thought perhaps every coloured stencil would be affected by a theme on a page, making them all the same.

The other thought I had was writing a bit of VBA that takes a stencil, iterates through every shape and looks for any colour that's not common to every stencil (so finding the colour that changes) and then programmatically altering the colour. But I've no idea how to change the colour of an image in a Master.

Hope you can help,

Rob

wapperdude

Here's simple macro.  Put it in the normal VBA  ThisDocuments window.


Sub mstrFillClr()

    For Each shpMst In Documents.Item("Stencil4.vss").Masters
        shpMst.Open.OpenDrawWindow
        Set vsoShp = ActiveWindow.Master.Shapes.Item(1)
        vsoShp.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(RGB(255,255,0))"
        vsoShp.CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEME(""FillColor""),THEME(""FillColor2""))))"
        ActiveWindow.Master.Close
    Next
End Sub


Editting the masters in the stencil will not automatically push down into the shapes on the drawing. 
Wapperdude
Visio 2019 Pro

wapperdude

Did a little hunting, and re-discovered this posting:  http://www.visguy.com/2008/02/25/edit-visio-masters-programmaticallythe-right-way/

There's also this post:  http://visguy.com/vgforum/index.php?topic=2152.0

The previous macro can be readily modified to edit the document stencil and push the changes into the shapes on the drawing pages:

Sub DocStencilFillClr()
'This macro edits the master shapes in the Document Stencil and the drawing pages.
'The first line contains the path and file name of the Visio drawing being edited.

    For Each shpMst In Documents.Item("D:\My Visio\Forum Stuff\EditMaster.vsd").Masters
        shpMst.Open.OpenDrawWindow
        Set vsoShp = ActiveWindow.Master.Shapes.Item(1)
        vsoShp.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "RGB(255,0,0)"
        vsoShp.CellsSRC(visSectionObject, visRowFill, visFillBkgnd).FormulaU = "THEMEGUARD(SHADE(FillForegnd,LUMDIFF(THEME(""FillColor""),THEME(""FillColor2""))))"
        ActiveWindow.Master.Close
    Next
End Sub


Wapperdude
Visio 2019 Pro

rainfordr

Awesome!

Thanks Wapperdude. I'll give these a look over and let you know how I get on :)

Yacine

Wouldn't it be smarter to have configurable shapes? i.e. having the colours of the shapes depending on custom data?
Yacine

rainfordr

Hi Yacine,

It may well be smarter. Tell me more. Although There are about 90 shapes in each stencil so I'd still need something to iterate through changing the colour in all likelihood.
For a bit of backstory, I've inherited stencil duties from someone else, but there was an issues with many of the masters which caused strange behaviours with connectors (due to shape sets being applied to incorrect layers and/or the parent portions of the shapes being set to whatever shape the master was created from). After much messing about my only solution was to copy the image as a PNG, delete the original sheets and replace with the PNG. This sorted the behaviour issues but now I need to reapply the shape data sets. So what I'm really looking for is a way to automate this entire process.

But I thought I'd just ask about the image part first.

Yacine

Can you upload 2-3 shapes, so we get a better idea of the task?
Yacine