Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: ben.oates on April 29, 2009, 11:52:20 AM

Title: Background Size
Post by: ben.oates on April 29, 2009, 11:52:20 AM
Hi all,

I have a background with 3 small logos on it.

I have set these logos up to space themselves evenly across the page regardless of how big the page is.

What I need to know is, when this page is set as a background, is it now possible to make that page stretch to match the size of whatever foreground page is using it so that these images will always space evenly across the top?

Many thanks,

Title: Re: Background Size
Post by: wapperdude on May 05, 2009, 12:58:06 PM
The background page does not normally scale to the foreground page, nor does it match the orientation.  Don't believe there is any existing automation for this.  Your options would be 1.) to make multiple backgrounds for the desired sizes and orientations, or 2.)  perhaps create some code that recognizes the foreground page and adjusts the background appropriately.

There is a danger with the second approach.  If two different (size and/or orientation) foreground pages reference the same background page, one of the two will have an incorrect background setting.  I think step 1.) would be quicker, easier, and less risky.

Title: Re: Background Size
Post by: Visio Guy on May 06, 2009, 05:11:56 AM
The page has a ShapeSheet which controls its size, along with other characteristics.

You can refer cells in a background page to cells in a foreground page. So, for the background, you could have something like:

PageWidth = Pages[Page-1]!ThePage!PageWidth
PageHeight  = Pages[Page-1]!ThePage!PageHeight

The problem is when you add another foreground page. Then the background will only follow "Page 1", and ignore page 2, 3, 4...

So this solution is only good for single-page documents. There are plenty of applications that require only one page, so this may be useful nevertheless.
Title: Re: Background Size
Post by: vojo on May 06, 2009, 07:49:52 AM
you might be able to pull this off with just using the "thepage" reference.
Ie since you select backup page when inserting new foreground page....and "thepage" references the
current page, this foregrnd page would set it.   Now I am not sure if you try to play some games where
each foreground page is a different size (may not be able to evenly do that)...if this works.

If you want individual sizes per foregrnd.   You could do group of shapes for background, use event on drop cell to pull up some custom properties that would set the size.   something like

width = prop.width_ratio * default width.

If you use the guard would not be allowed to accidently change shape size or move
(same as the protection stuff).

With protections for size, location, format....probably dont need to worry about selecting inadvertently
protection against delete should make sure you do loose it.

I am not too fluent with layers...but you could use layering to help with this (backgrounds on 1 layer foregrnd on another.....hide background until finished....then enable).

finally, if you really want to go where few have could look at a drop down to define which foregrnd sets the size.   Use quotes and getval to define the "[1]" piece of the equations above. 
Wont kid you...this will end up being real subtle to achieve and may be more work than is worth it.

Just some thoughts.
Title: Re: Background Size
Post by: ben.oates on May 11, 2009, 05:39:41 AM
Thanks for the feedback guys. All very helpful.

Unfortunately, this will be a multi-page document with pages of different sizes. However, the images will be evenly spaced across the edges of the document so a combination of your feedback has given me a new idea/problem.

If I made these images space themselves in the ShapeSheet, used the GUARD function and turned them into a Stencil of some kind, how could I make Visio add this named stencil to every new page?

This way, I could remove background pages completely and the images I need people to include would be enforced nonetheless. It might make file sizes a bit bigger but that's not a concern.

Thanks again.
Title: Re: Background Size
Post by: aledlund on May 11, 2009, 08:34:00 AM
a note from the side to stir the pot

Title: Re: Background Size
Post by: ben.oates on May 11, 2009, 09:52:02 AM
Thanks aledlund. I managed to cobble together something similar, except it drops itself on the PageAdded event.

In case this helps people in the future, my master does many of the things mentioned in that link through code:

Private Sub Document_PageAdded(ByVal Page As IVPage)
    Set masShape = ActiveDocument.Masters.ItemU("Background Images")
    Set bgShape = ActivePage.Drop(masShape, 0, 0)
    bgShape.CellsU("Width") = 0
    bgShape.CellsU("Height") = 0
    bgShape.CellsU("PinX") = 0
    bgShape.CellsU("PinY") = 0
    bgShape.CellsU("LocPinX") = 0
    bgShape.CellsU("LocPinY") = 0
    bgShape.CellsU("LockTextEdit") = 1
    bgShape.CellsU("NoObjHandles") = 0
    bgShape.CellsU("LockSelect") = 1
    bgShape.CellsU("LockMoveX") = 1
    bgShape.CellsU("LockMoveY") = 1
    bgShape.CellsU("LockDelete") = 1
    bgShape.CellsU("SelectMode") = 0
    bgShape.CellsU("DisplayMode") = 1
End Sub

The "Background Images" master is made up of 3 images that cannot be stretched - but have GUARD set on their location to make them spread out top left, center and right of the page against ThePage PageHeight and PageWidth. When the master is added, you have to move it to the bottom left otherwise it still offsets the 3 images contained within. I made it 0 height and width so that nobody would click it.

Thanks for the help guys.
Title: Re: Background Size
Post by: Visio Guy on May 11, 2009, 10:05:21 AM
I usually make some sort of "foreground title block" shape in these circumstances. You can set size and position formulas such that the shape automatically fits the page onto which you drop it.

For instance, a "header" shape might have formulas like this:

LocPinX = GUARD(0)
LocPinY = GUARD(Height)
PinX = GUARD(0.25in)
PinY = GUARD(ThePage!PageHeight-0.25in)

Note: 0.25in is a margin to keep the shape off the non-printable edges.

There is more information on fixing a shape's position on an arbitrary page in this article:
Number Your Pages Visually (
Title: Re: Background Size
Post by: Yacine on May 11, 2009, 10:38:30 PM
I faced a similar problem, having to set the drawing frame of multipe page drawings.

The solution is quite simple, but requires either some disciplin from your users (that's the way we chose) or to block the edition of certain page properties (--> guards in the shape sheet).
We ask our users to change ONLY the drawing scale when they wish to adjust the page size. That works pretty fine.
In the enclosed example, you'll notice that the 500x200 mm rectangle has a quite different size on page 1 and 2.
You'll see also that font sizes don't depend on the page scale (both page names have font size 60 and the same size). You'll overcome this problem by using text shapes with font sizes that depend on their height.

The 3 shapes of the background have the same look on both foreground pages as required.
Title: Re: Background Size
Post by: wapperdude on May 12, 2009, 12:13:45 AM
You were actually able to have users that were disciplined?     ???  Wow!   :o
Title: Re: Background Size
Post by: AndyW on May 12, 2009, 02:08:14 AM
I adjust the background to fit my current page, using the WindowTurnedToPage event.

Private Sub myVsoApp_WindowTurnedToPage( _
    ByVal Window As IVWindow)
    Dim vsoPage As
    Dim vsoBackPageSheet as Visio.Shape

    Set vsoPage =

    Set vsoBackPageSheet = Window.Document.Pages("BACKGROUND").PageSheet
    With vsoPage.PageSheet
        vsoBackPageSheet.CellsU("PageWidth").FormulaU = .CellsU("PageWidth").FormulaU
        vsoBackPageSheet.CellsU("PageHeight").FormulaU = .CellsU("PageHeight").FormulaU
    End With
End Sub
Title: Re: Background Size
Post by: Yacine on May 12, 2009, 01:22:00 PM
You were actually able to have users that were disciplined?     ???  Wow!   :o
Actually yes. Let them distroy 2 or 3 drawings and direct them to your tutorial as only answer.
Very educative ;D (the sadist in me)
I have to add, that I have only abt. 10 people to handle.
Title: Re: Background Size
Post by: Yacine on May 12, 2009, 01:26:06 PM
Unfortunately, this will be a multi-page document with pages of different sizes.
With your code all the pages should get the same size  ???