News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Page / Shape: Name vs NameU vs Index vs ID

Started by wapperdude, May 17, 2018, 07:39:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

Visio's handling of naming comes up frequently in a variety of posts.  So, what's going on???  Well, here are some links for the official statements:
Name vs NameU:  https://blogs.msdn.microsoft.com/visio/2006/07/27/name-and-nameu/
Shapes:  https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-nameu-property-visio
Pages:  https://msdn.microsoft.com/en-us/vba/visio-vba/articles/page-nameu-property-visio

To illustrate the relationships for pages as listed in the post title, the following simple macro was used to check out page naming conventions.  The process involved:
1) new document, adding 3 pages to get a total of four.  Keep default (original) names and order.
2) run macro.  The list shows the expected and unexpected.  Index is just the order of things.  Name and NameU are identical.  ID...what's up with that???
3) change the names of the pages, but keep the order.  Run macro.  This is the special case, happens only first time.  Name and NameU update identically.  Nothing else changes.
4) change names a 2nd time.  Run macro.  Name updates, but NameU keeps its value.  In fact, NameU will remain at this value unless code is used to specifically modify it.
5) change the page order.  Run macro.  Name, NameU, and ID track with each other.  Indexing stays unchanged.  That is, Index 1 refers to whoever is on first.  Thus, the "index" of a page will update depending upon where it is in the order.

Results of each macro run have been copied and pasted following the code.

A similar analysis for shapes could be done with update to the macro.

HTH
Wapperdude

Sub ReNamePg()
'Simple macro that shows relationship for Page: Name, NameU, Index, and ID

    Dim vsoPg As Page
    Debug.Print ""
    Debug.Print "Revised Names, New Order:"     'Manually change this for desired section title
    Debug.Print "Name", "NameU", "Index", "ID"
    For Each vsoPg In ActiveDocument.Pages
        Debug.Print vsoPg.Name, vsoPg.NameU, vsoPg.Index, vsoPg.ID
    Next
End Sub

Quote
Original Names, Order:
Name          NameU         Index         ID
Page-1        Page-1         1             0
Page-2        Page-2         2             4
Page-3        Page-3         3             5
Page-4        Page-4         4             6

New Names, Original Order:
Name          NameU         Index         ID
One           One            1             0
Two           Two            2             4
Three         Three          3             5
Four          Four           4             6

Revised Names, Original Order:
Name          NameU         Index         ID
Pg1           One            1             0
Pg2           Two            2             4
Pg3           Three          3             5
Pg4           Four           4             6


Revised Names, New Order:
Name          NameU         Index         ID
Pg2           Two            1             4
Pg1           One            2             0
Pg4           Four           3             6
Pg3           Three          4             5
Visio 2019 Pro

alkali

This topic seems that it's only confusing the people. I don't realy see any advantage of this behavior.
Why isn't it easily possible to show at least both names (Name and NameU) in the Shape Sheet.
Or make it even editable.


AndyW

This is done for locale support which is especially relevant to the Visio internal cells and names. Where the Name may have the locale version but the NameU (universal) will have the English (well American) name.
Live life with an open mind

wapperdude

Thought I ought to add a summary observation to these results...
  > The page ID is assigned when page is added to document.  It doesn't change. 
  > The page Index is the sequential ordering/placement of the pages.  It isn't determined by any other page property.  It merely tells you who's first, what's second...
  > The page NameU is the universal name.  It can be changed only once.  After that, it no longer changes.
  > The page Name is local to the document.  It may be changed numerous times.  However, beginning with 2nd change, it no longer tracks with NameU. 

>>> It is important to note the differences between Name and NameU, otherwise unexpected results may arise.
Visio 2019 Pro

wapperdude

One more add...the following code has 2 sections.  1st section set correspondence between page number and page name, 2nd section re-syncs the Name and NameU.

Sub reNumPgNames()
    Dim pBeforgAry() 'As Variant
    Dim vPg As Visio.Page
    Dim vPgs As Visio.Pages
   
    For i = 1 To ActiveDocument.Pages.Count
        Set vPg = ActiveDocument.Pages.Item(i)
        vPgTmpname = "Pg-" & vPg.Index
        If StrComp(vPg.Name, vPgTmpname, vbTextCompare) <> 0 Then
'            Debug.Print vPg.Name & "  " & vPgTmpname & "  " & vPg.Index & "  " & vPg.ID
            vPg.Name = vPgTmpname & "x"
            vPg.NameU = vPg.Name
'            Debug.Print vPg.Name & "  " & vPg.NameU & "  " & vPg.Index & "  " & vPg.ID
        End If
    Next
   
'    Call fixPgNames
       
    For i = 1 To ActiveDocument.Pages.Count
        Set vPg = ActiveDocument.Pages.Item(i)
        vPg.Name = "Pg-" & i
        vPg.NameU = vPg.Name
        Debug.Print vPg.Name, vPg.NameU, vPg.Index, vPg.ID
    Next
Visio 2019 Pro

Browser ID: smf (is_webkit)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 236 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1125KB.
Tokens: post-login.
Cache hits: 14: 0.00150s for 26,766 bytes (show)
Cache misses: 3: (show)
Queries used: 17.

[Show Queries]