1

I'm not new to Visio nor to programming but I am new to developing in Visio. I'm using 2007 and am creating my own custom shapes with Shape Data. I want to create a UniqueID for all my shapes in the context of the drawing. I have created a Shape data element called 'Shape UniqueID'. (ShapeSheet Prop.Shape_Unique_ID) I tried to generate a unique ID (Shape.UniqueID property), using the formula syntax below, in the ShapeSheet 'Value' cell for the property :
=UniqueID(visGetOrMakeGUID) and =UniqueID(1) But Visio does not recognize this as a valid Formula..

I also tried to use DATA1(): =Guard(Data1()) That gives me a unique value BUT it does not update if you copy the shape.

I've dowloaded the 2007 SDK and can't find a Shapesheet function to read the properties.

I have also seen that you can set the page so UniqueIDs are always on shapes used but I can't figure out how to turn it on.

My "preference" is to use a Shape Data element and set it BUT......

Any Ideas would be appreciated? Thanks ... Scott

Scott M
  • 7
  • 1
  • 3

1 Answers1

3

[Note this answer is rough duplicate of the one here ]

UniqueIDs are only accessible in code, ie, there's no ShapeSheet function that'll return a unique ID (GUID).

By default a shape starts off without a UniqueID so you have to assign it in code. Some shapes such as the off page connector shape store the unique IDs in the ShapeSheet so that they can track which shape is connected to which, but this is managed by an addon.

You can store a GUID in a ShapeSheet cell (usually a User cell), but generally if you have a reference to a shape to read a cell then you also have the means to read the .UniqueID property as well. If you're looking for other ways to identify a shape then shp.ID (or the ID() ShapeSheet function) will return an ID that's unique to the page, so that may be something to consider as well

Here's some sample code that demonstrates how to use UniqueIDs:

Sub UniqueIDsDemo()

Dim vPag As Page
Set vPag = ActivePage

Dim vShp As Shape
Set vShp = vPag.DrawRectangle(1, 1, 1, 1)
Debug.Print vShp.NameID & " UniqueID = '" & vShp.UniqueID(visGetGUID) & "'"

Dim sGUID As String
sGUID = vShp.UniqueID(visGetOrMakeGUID)

Debug.Print vShp.NameID & " UniqueID = '" & vShp.UniqueID(visGetGUID) & "'"

vShp.AddSection visSectionUser
Dim rowIdx As Integer
Dim cellName As String
cellName = "UniqueID"
rowIdx = vShp.AddNamedRow(visSectionUser, cellName, visTagDefault)
vShp.CellsSRC(visSectionUser, rowIdx, visUserValue).FormulaU = sGUID

Debug.Print vShp.NameID & "!User." & cellName & " = '" & vShp.CellsU("User." & cellName).ResultStrU("") & "'"

End Sub
JohnGoldsmith
  • 2,638
  • 14
  • 26