There is an excellent paper by Tim Davenport called Designing Shapes for Use with Themes in Visio 2007. It is listed in the Error: Reference source not found section of this module and covers a few more details than is covered in this section.
User issues What is a theme?
A theme in Visio is a set of colors and effects that can be applied to a drawing with a single click. Themes are a quick and easy way to give a drawing a professionally designed look.
Themes are divided into two parts: Theme Colors and Theme Effects each of which controls specific formats within shapes.
Themes are displayed in the Design tab of the ribbon interface.
What happens to a shape when a theme is applied or removed?
A Theme Color contains color assignments for the following color attributes of a shape:
-
Text
-
Line
-
Connector
-
Fill
-
Fill pattern
-
Shadow
-
Accents 1-5 (covered in Tim Davenport’s paper)
-
Background
A Theme Effect contains formatting attributes for:
-
Text Font
-
Line pattern, weight, transparency and rounding
-
Fill pattern and transparency
-
Shadow style, transparency, offset, magnification, and direction
-
Connector pattern, weight, transparency, rounding, and arrowhead style and size
When a Theme Color or a Theme Effect is applied the colors and formatting defined within the theme are applied to all of the shapes on a page. Cells within each of the shape’s ShapeSheet are modified to receive the Theme function.
Try It! -
Start by creating a new blank drawing. This will create a blank drawing without any stencils opened. Draw a shape on a page.
-
Look at its ShapeSheet and look at the FillForegnd cell. If it is filled as white, the value will be 1.
-
Select a Theme from the Design tab.
-
Look at the ShapeSheet again. The formula in the FillForegnd cell is Theme(“FillColor2”).
Also, a user defined cell User.msvThemeColors and/or User.msvThemeEffects is added to the shape. These cells contain the identity of the theme from which the shape’s Theme function will be evaluated.
Each cell controlled by the theme will have a similar formula placed into it.
-
Expand the Theme selection from the Design tab and uncheck Apply Themes to New Shapes.
-
Draw a shape using the drawing tools. If no theme is currently applied to the drawing, the FillForegnd cell will have a value of 1 which it inherits from a built in master. If a theme has been applied to the drawing the FillForegnd cell will have a value Theme(“FillColor2”). If the theme is subsequently removed (by applying the None theme) the cell contents re-inherit from the master.
-
Draw a shape, open its ShapeSheet and enter the value 2 (red) into the FillForegnd cell. The FillForegnd cell now has a local override in the cell and thus does not inherit this cell from a master. The FillBkgrd has a value of 0.
-
Apply a theme to this shape. The contents of the cell after application of the theme will be FillForegnd=Theme(“FillColor2”)+ThemeRestore(0). And FillBkgnd=Theme(“FillColor”)+ThemeRestore(2). If the theme is subsequently removed the cell contents return to their original state. The ThemeRestore function is used to preserve the original contents of the shape so that they may be restored if the theme is removed.
What happens to a page when a theme is applied/removed?
When a theme is applied new user cells are introduced into the page’s ShapeSheet. The user cells are User.ThemeColors and User.ThemeEffects. These cells contain the identity of the themes applied to the page.
In the image above the value of 3 for User.msvThemeColors is referencing one of the built in color themes. User.msvThemeEffects is referencing a custom Theme Effect.
How is a theme different from Color Schemes in previous versions of Visio?
In earlier versions of Visio, the Color Schemes feature provided users a limited ability to apply formatting themes in templates that were designed to support the feature. To apply Color Schemes to shapes, shape developers had to assign a style to the shapes, selected from a set of hidden Color Scheme styles. When users then applied a color scheme to the drawing, Visio changed the colors used in the color-scheme styles so that any shapes that used styles based on them would also change color.
The Theme feature beginning in Visio 2007 uses a completely different approach. A shape does not need to have a style assigned to it to support themes. In fact, the feature does not use styles at all. You can apply themes to any shape or group of subshapes, unless they are protected in some way from themes or formatting.
If you draw a rectangle by using the Rectangle tool and then apply theme colors and theme effects to the page, the rectangle immediately takes on all the applicable theme-formatting attributes listed above, and no further action is required on your part. In effect, applying a theme works the same way as applying manual formatting.
In Visio 2003, when a Color Scheme is applied the following action section gets added to the page. Note the Action cell with the formula RUNNADDON(“CS”). If a drawing that was created in Visio 2003 is opened in Visio 2007 or later, the RMA Color Schemes… still shows in the menu because this Actions section is still part of the document. Also, the add-on “CS” is included in Visio 2007 so selecting the Color Schemes… menu will still work. This Actions section will remain in the document until a Theme is applied. Once that is done, this row of the Actions section will be removed and Color Schemes will no longer be available for this drawing.
How to prevent themes from being applied
There are several approaches to protecting shapes or individual cells from the effects of applying a theme.
The LockFormat cell in the Protection section of a shape’s ShapeSheet locks all formatting of a shape so that it cannot be changed. This includes any formats applied through the user interface as well as formats applied through styles or themes.
The LockThemeColors cell in the Protection section of a shape’s ShapeSheet prevents the application of Theme Colors to the shape. This does not prevent changes in formats done through the user interface such as setting the fill color or line weight. It does also not prevent the application of a Theme Effect.
The LockThemeEffects cell in the Protection section works like the Lock ThemeColors cell except that it protects against the application of a Theme Effect, but does not prevent the application of a Theme Color of changes in formats through the user interface.
Using cells in the Protection section of the ShapeSheet protects the overall shape. The protection of individual formats can be done using the Guard and ThemeGuard functions to protect an individual cell in the ShapeSheet.
Wrapping a cell formula with a Guard function protects just that cell from the application of changes made through the user interface, the application of a theme or the application of a style.
Try It! -
Draw a shape and in the FillForegnd cell of the ShapeSheet place the formula Guard(3). This sets the shape’s color to green.
-
Try to change the fill color through the user interface. The shape color does not change.
-
Try to change the fill color by applying a theme color or a style. The shape color does not change and the cell contents are unchanged.
Note:
|
In Visio 2010 the roles of the FillForegnd and FillBkgnd cells are reversed. A GUARDed formula in the FillForegnd cell will automatically be moved to the FillBkgnd cell upon the application of a theme.
|
Wrapping a cell formula with a ThemeGuard function protects that cell from the application of a theme. If the cell is changed through the user interface the ThemeGuard remains, but the formula that it wraps is replaced.
Try It! -
Draw a shape and in the FillForegnd cell of the ShapeSheet place the formula ThemeGuard(3). This sets the shape’s color to green.
-
Try to change the fill color by applying a theme color. Nothing happens.
-
Try to change the fill color through the user interface by setting the color to yellow. The cell contents are changed to THEMEGUARD(RGB(255,255,0)) which changes the shape color to yellow. Note that the ThemeGuard function is not replaced so a theme can still not be applied to the shape.
Copy a theme from another drawing
You may have gone to the effort of creating a custom theme in a drawing or received a drawing from someone else that has a theme you like. How do you add that theme to a different drawing?
The process is very straight-forward. Just copy a shape that has the desired theme applied to it. Paste it into your drawing where you want to add the theme. The shape and the theme are added to the drawing. Now you can delete the original shape and the new theme will remain.
Developer issues Designing shapes for themes
Many shapes work well with themes without any extra work. However, it is at times desirable to control which color associated with a theme (there are several) gets applied to a shape. For example, there are 5 complementary accent colors in each theme. To apply the second accent color to the FillForegnd cell of a shape enter the following formula into the FillForegnd cell.
FillForegnd =THEMEGUARD(THEME("AccentColor2"))
Then if the applied theme is changed, the shape will display the second accent color of the new theme.
This is particularly useful for group shapes that have several colors associated with the group components.
CELLISTHEMED()
Applying the CELLISTHEMED function to a shape lets you assign appropriate parts of a theme's formatting to a shape but retain the ability to override other parts of the theme's formatting with your own manually applied formatting. If you subsequently reapply the theme, any manual formatting is overridden and the shape takes on the all theme's formatting.
Try It! -
Draw a shape and in the FillForegnd cell of the ShapeSheet place the formula
THEMEGUARD(IF(CELLISTHEMED(TRUE),THEME("AccentColor2"),SETATREFEXPR()))
-
If the value of CELLISTHEMED is TRUE, the shape takes as the fill foreground color the theme's Accent 2 color. If you subsequently apply a fill color to the shape manually, Microsoft Office Visio sets the value of CELLISTHEMED to FALSE and stores the manually set color in SETATREFEXPR.
-
Change the fill color through the user interface by setting the color to yellow. The formula in the FillForegnd cell changes to
THEMEGUARD(IF(CELLISTHEMED(TRUE),THEME("AccentColor2"),SETATREFEXPR(THEMEGUARD(RGB(255,255,0)))))
Try It! -
Open the Shapes Module 1.vss from the Samples folder for this course. Drop the shape Use Accent Colors onto the drawing page. Subselect the red arrow and open its ShapeSheet. Note the formula in the FillForegnd cell. THEMEGUARD(IF(CELLISTHEMED(FALSE),SETATREFEXPR(THEME("AccentColor2")),SETATREFEXPR(RGB(255,85,85)))). The other arrows have similar formulas. The image below is the shape with no theme applied.
Figure . Shape Use Accent Colors, no theme applied
It uses the CELLISTHEMED function to display a shade of red if the shape is not themed and to display the second accent color of the theme when a theme is applied.
-
Apply a theme color to the shape. In the image below the Office theme is applied.
Figure . Shape Use Accent Colors, Office them applied
-
Set the theme to None. The shape reverts back to its original colors.
-
Add the shape Use Tint to the drawing. Apply the Office theme color. The image is below.
Figure . Shape Use Tint, Office theme applied
-
Subselect the arrow at the 3 o’clock position. The FillForegnd cell contains the formula
THEMEGUARD(IF(CELLISTHEMED(TRUE),TINT(THEME("FillColor"),30),SETATREFEXPR(RGB(255,85,85))))
Each arrow has a similar formula that uses a TINT of the “FillColor”. The TINT and SHADE functions provide a way to create a color that is a tint or shade of another color. They adjust the luminosity (the L in the HSL color model) of the color by the integer in the cell formula. This number has a range of 0-240.
-
Add the shape Use Blend to the drawing. Apply the Office theme color. The image is below.
Figure . Shape Use Blend, Office theme applied
-
Subselect the arrow at the 3 o’clock position. The FillForegnd cell contains the formula
THEMEGUARD(IF(CELLISTHEMED(TRUE),BLEND(THEME("FillColor"),THEME("AccentColor2"),0.2),SETATREFEXPR(RGB(255,85,85))))
Each arrow has a similar formula that uses a BLEND of “FillColor” and “AccentColor2”. The third parameter is a proportion of each color to use. It has a value from 0-1.
Note:
|
Tim Davenport’s paper covers more examples of using ShapeSheet functions to control theme colors.
|
Where is a theme stored?
Any themes created by the user are stored as a Master on the Document Stencil. However, if you look at the Document Stencil, you won’t see them because the theme master has its Hidden property set to true.
These hidden theme masters do show in the Drawing Explorer window under the Masters collection.
Note:
|
The built-in themes cannot be seen in the Drawing Explorer window and cannot be changed. They can be duplicated and changes applied to the duplicate.
|
Does a theme have a ShapeSheet and how do I see it?
You can access the theme’s ShapeSheet only for themes that are created by the user. The built-in themes are not accessible. Use the Drawing Explorer window to see the user created theme masters. Right click the master and choose Edit Master Shape. A master drawing window is opened. Right click the master shape and choose Show ShapeSheet.
The User-defined Cells section of a color theme ShapeSheet is shown below. Note there are cells for each color displayed in the Edit Theme Colors dialog.
Figure . User-defined cells for a Theme Color
Below is the User-defined cells section for a Theme Effect. There are cells corresponding to every setting within the Edit Theme Effects dialog.
Figure . User-defined cells for a Theme Effect
Does a copied theme inherit from the original?
No. This can be verified as follows.
-
Duplicate the Office theme color. This will create Office.1.
-
Duplication Office.1 to create Office.2.
-
Edit the main fill color for Office.1 and save the changes. Note that Office.2 is unaffected.
Apply a theme through automation
This is done by setting ThemeColors or ThemeEffect property of the page object. Here is example VBA code to set the Theme Color.
Sub ApplyTheme()
ActivePage.ThemeColors = "Office.1"
End Sub
Duplicate a theme
The built-in themes of Visio are not in the Masters collection of the document. You can copy a theme that is a master within a document’s master’s collection by using the Drop method of the Masters collection. The inputs are a reference to the master to be duplicated and the position of the drop coordinates.
Sub DuplicateTheme()
ThisDocument.Masters.Drop ThisDocument.Masters("Office.1"), 0, 0
End Sub
You can create a new theme and then fill in its values through automation with the AddEx method of the Masters object.
-
Use Masters.AddEx() to create a master of type visTypeThemeEffects or visTypeThemeColors.
-
Open the Master.
-
Modify the various msvTheme* cells in the User-defined Cells of the ShapeSheet. See Figure . User-defined cells for a Theme Color and Figure . User-defined cells for a Theme Effect for a complete list of these user-defined cells.
-
Close the Master
-
Set Page.ThemeColors or Page.ThemeEffects to apply the new theme to the page.
Getting rid of unused themes
Unused themes, along with unused data graphics, and unused styles can be removed through the user interface by accessing the Remove Hidden Information menu.
To do the equivalent work through automation use the RemoveHiddenInformation method of the document object and pass to it the type of information to be removed.
Example: (VBA)
Public Sub RemoveHiddenInformation_Example()
ActiveDocument.RemoveHiddenInformation visRHIPersonalInfo + _
visRHIStyles
End Sub
The macro above removes personal information and unused themes, styles, and data graphics.
Share with your friends: |