Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on June 10, 2021, 10:38:24 AM

Title: page changed event
Post by: perry59 on June 10, 2021, 10:38:24 AM
I am using the "pagechanged" event to capture the renaming of sheets in a drawing, but for my purposes it comes  up a little short.
while this event will tell me what the page is NOW named, there seems to be no  way to find what the name of the page was BEFORE the event.
I have a backend database connected to my drawings via an addin which tracks parts etc., these part references includes the name of the sheet on which they reside.
if a user renames a page I want to edit the database to change the sheet names of these part references but I see no way of doing that.
Does anyone have any ideas of a work around?
Thanks
Title: Re: page changed event
Post by: perry59 on June 13, 2021, 12:42:36 PM
well bummer, and I see nothing in the sheet or document shapesheets that would help either :(
Title: Re: page changed event
Post by: wapperdude on June 13, 2021, 01:30:04 PM
The only thing that occurs to me...
1) at some point save initial page names to some dedicated shapesheet location, perhaps in User section.
2) at document close, save current page names.
3) at subsequent file openings, if there's a mismatch, ask if old name be updated.  That way,if same page changed again, there's a previous name available.

... or something like that.

Title: Re: page changed event
Post by: Nikolay on June 13, 2021, 01:56:51 PM
Name may be okay when you just write a macro to be used like once or twice or changed when needed...
For a long-term solution, maybe you could consider using something like page ID instead of page name.
Then you don't even need to track it with page changed event, because it never changes.
Title: Re: page changed event
Post by: perry59 on June 13, 2021, 05:11:32 PM
Both interesting ideas, and food for thought, surely better than the crazy scheme I came up with.

As I mentioned, this is used in the context of an adding which also is linked to a backend database. I already have tables which track document names and sheet names. I could put an extra column in my sheets table for a unique ID (GUID). Then when any sheet is added to a drawing assign it a GUID (or use its internal ID) and keep it in a user cell. Anytime a sheet is renamed or deleted in the future I could compare the sheet ID's in my database to ID's in the physical drawings. But if a database project includes multiple drawings with multiple sheets that would mean opening up every drawing and going through every sheet anytime a user deletes or renames a page. I quickly realized I would be despised and nixed that idea!

I think I will try a combination of both your ideas if you don't mind. I'll give it some trial runs and let you know how it goes.
Thanks!
Title: Re: page changed event
Post by: Visisthebest on June 13, 2021, 05:42:21 PM
Tracking based on UniqueIDs/GUIDs is the way to go!
Title: Re: page changed event
Post by: scott on June 28, 2021, 03:16:23 PM
There's an application event called WindowTurnedToPage that fires whenever you change to a different page. You could use that in conjunction with the PageChanged event, e.g., use WindowTurnedToPage to write the current page name to a user cell in the page each time the page is activated, then use PageChanged to detect that the current name is different than the previous name and take whatever action you want. I've attached a diagram with a simple version of this idea that pops a message box when the new and previous names don't match.
Title: Re: page changed event
Post by: perry59 on July 26, 2021, 10:14:25 AM
I just did it the easy way. Made user cells for the page name and a GUID. If the user renames a sheet, it updates those cells and the database, so it never even bothers the user. Seems to be working ok so far.
Thanks all !