Visio Guy

Visio Discussions => Programming & Code => Topic started by: bouananimeher on September 23, 2011, 09:52:22 AM

Title: Identifying Visio Pages with Unique IDs
Post by: bouananimeher on September 23, 2011, 09:52:22 AM
Hi ,
Well i am pretty new here and i am a beginer ,so i am asking if there is way to identify a visio page by it's unique ID or  any other ways , like tha case of Shapes which are identified by : Shape.UniqueID and Masters : master.uniqueID ...
Thank you
Title: Re: Identifying Visio Pages with Unique IDs
Post by: Paul Herber on September 23, 2011, 11:04:10 AM
The Page.ID is constant, it doesn't change when the page gets renamed or the page order changes. The number may be reassigned though if the page is deleted and then a new page created.
http://msdn.microsoft.com/en-us/library/ff766565.aspx (http://msdn.microsoft.com/en-us/library/ff766565.aspx)

How about when the page is created add a User defined cell and add your own unique ID to that cell.
Title: Re: Identifying Visio Pages with Unique IDs
Post by: bouananimeher on September 23, 2011, 11:31:36 AM
Thank you for aswering :) , no i am facing another problem  :-[ , i have some macros that are fully functional in vsd document (Dessin.vsd) and for now i am trying to get them functional for every document i create , but the problem is when i embed them into a Stencil some errors come out and i do not actualy know the reason , could you have an explanation for that ?
Title: Re: Identifying Visio Pages with Unique IDs
Post by: Jumpy on September 23, 2011, 02:29:00 PM
Could you say more about the errors? It could matter, how the macros are called. Or the code project of the stencil has to be known to the drawing or vice versa.

Somewhere in this forum is a near tutorial like thread about placing code in stencils.
Title: Re: Identifying Visio Pages with Unique IDs
Post by: bouananimeher on September 26, 2011, 08:15:10 AM
i have to Marcos , Macro1 which is processing on an IE instance , and Macro2 wich deals with MSSQL , i've created to buttons for these macros to execute them , and here is the souce code to do that : Sub CreateMyButtonBar()
Dim CB As CommandBar
Dim CBS As CommandBars
Set CBS = Application.CommandBars
Set CB = CBS.Add(CommandBarName, msoBarFloating)
AddButtonToBar CB, "Macro1", "Run security application", 186
AddButtonToBar CB, "Persist", "Persist Data", 180
CB.Visible = True
End Sub
Private Sub AddButtonToBar(Bar As CommandBar, _
MacroName As String, _
Caption As String, _
Button As Integer)
Dim CBC As CommandBarControl
Set CBC = Bar.Controls.Add(msoControlButton, 1, , , True)
CBC.Style = msoButtonAutomatic
CBC.FaceID = Button
CBC.Caption = Caption
CBC.OnAction = MacroName
End Sub
the problem still now where should i put the call of the function CreateMuButtonBar inside the page "ThisDocument" of the Stencil  in order to create these two buttons that appear each time i tried to open visio or when i create a new docuement or when i am working on an existing docuement !!?



Title: Re: Identifying Visio Pages with Unique IDs
Post by: Visio Guy on September 27, 2011, 09:32:16 AM
Visio pages also have a "page sheet", a ShapeSheet for the page. In this respect, they exhibit some shape-like behavior, from an automation standpoint.

You get at the shape-ish part of a page using visPg.PageSheet. Here we get a GUID from a page, just like we do for a shape:


'...
Debug.Print Visio.ActivePage.PageSheet.UniqueID(Visio.VisUniqueIDArgs.visGetOrMakeGUID)
'
'Result: {A8A24720-0C84-4FDC-8551-4265247DF2F6}



You would still need to loop through all the pages in a document find the right page with the right GUID, something like:


Function GetPageByID(ByRef visDoc as Visio.Document, ByVal guid as String) as Visio.Page

  Set GetPageByID = Nothing '...the default result.

  Dim pg as Visio.Page
  Dim guidPage as String

  For Each pg in visDoc.Pages
    guidPage = pg.PageSheet.UniqueID(visio.VisUniqueIDArgs.visGetGUID) '...get-only, not get or make!
    If (guidPage = guid) Then
      Set GetPageByID = pg
      Exit Function
    End If
  Next

End Sub

Title: Re: Identifying Visio Pages with Unique IDs
Post by: bouananimeher on September 27, 2011, 12:20:14 PM
Hi,

Thank you so much it solve a big problem. Now I can update an existing Diagram :D
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 59 (show)
Files included: 25 - 925KB. (show)
Memory used: 766KB.
Tokens: post-login.
Cache hits: 7: 0.04829s for 22,302 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]