[Tutorial] Background text changes depending on the frontpage used

Started by Lars-Erik, April 24, 2008, 06:48:08 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Lars-Erik

Background info:

What i needed was a way to display text on the background that would be different depending on the foreground. Cause the border and title block of my drawings need to change when the paper size is changed, I made backgrounds containing the border and title block. Each of my Visio files contains two pages. The problem occurred when both the drawings in the Visio file are using the same background, they will have the same data in there title blocks. To get past this problem i had to find a way to make the text change depending on the foreground.

Using the Visio UI I was able to make a shape display the background page name as text. The command for this according to the ShapeSheet of the shape was =BKGPAGENAME(). After some searching on the MSDN site i found a command that looked alot like it, =PageName(). After trying this command i noticed this did exactly what i had hoped. If you put this command on a background it will show the name of the current page, if the current page happens to be a foreground page it will show that name.

A simple second step would be to make an if statement change the text depending on the =PageName() command and you would be done. This however turned out to be a bit harder then I hoped. After creating the if statement i noticed that it doesn't play nice with strings. Because i don't want to name my pages 1 and 2. I got around it bij naming them 1; Pagename and 2; Pagename. Cause I don't want to force someone to add unwanted data in there page name. A solution would be to replace the PageName() with PageNumber(). If you alter the if statement to check for the page index.

The code:

So, here goes add custom properties to your document. These will function as a source for our data. (what will be displayed).
Example: The User.Properties is "PFD Description;P&ID Description;PFD Drawing no.;P&ID Drawing no.;Proj. no.;Order no.;Customer name"

Now on every background you have. Add the following text field

=IF(PAGENUMBER()=1,INDEX(0,TheDoc!User.Properties),INDEX(1,TheDoc!User.Properties))

It checks what page is showing, if its page with index 1, it will get the documents User.Properties field. The index command will make it sellect the first (0 ;'s) data it finds. If its not the first page it will get the 2nd data (1 ;'s ).

In this case the text field will show PFD Description on page with index 1, and P&ID Description on the page with any other index.
If you have more pages you will have to add more if statements.

Fairly straight forward, though for some reason I find it hard to explain clearly. If you cant get it to work let me know!
!!!This code will check for page order changing the page order will mess up the effect of this code!!!

Check the tutorial on preventing unwanted user input to lock the page order
http://visguy.com/vgforum/index.php?topic=15.0

Also for some further help:
http://msdn2.microsoft.com/en-us/library/aa224205(office.11).aspx
http://msdn2.microsoft.com/en-us/library/aa223748(office.11).aspx