Visio Guy

Visio Discussions => General Visio => Topic started by: analogman on March 09, 2020, 04:01:57 PM

Title: How to Find a Shape with a Given ID?
Post by: analogman on March 09, 2020, 04:01:57 PM
Greetings,

I'm looking at a shape in a custom stencil and I see references to cells on a different sheet, Sheet.5. I cannot figure out how to see Sheet 5.I've highlighted all of the sub shapes that make up the  shape but none of them bring up a shape sheet for sheet 5.

Is there anyway to see how many shape sheets exist for a complete shape? Might there be more than one way to open a shape sheet?

Thanks,
Dan
Title: Re: How to Find a Shape with a Given ID?
Post by: wapperdude on March 09, 2020, 06:56:29 PM
On the ribbon, left hand side, activate the Window Explorer.  You can then navigate within the WE, expand the pages, the shapes within a page, etc.

This Visio2010 helps explain it:  https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.oreilly.com/library/view/microsoft-visio-2010/9781849680141/ch02s05.html&ved=2ahUKEwj2wafViI7oAhW9JzQIHeiXAyoQFjAGegQIARAB&usg=AOvVaw2MZKnzkbKjQXArRns5ghby (https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.oreilly.com/library/view/microsoft-visio-2010/9781849680141/ch02s05.html&ved=2ahUKEwj2wafViI7oAhW9JzQIHeiXAyoQFjAGegQIARAB&usg=AOvVaw2MZKnzkbKjQXArRns5ghby)
Title: Re: How to Find a Shape with a Given ID?
Post by: analogman on March 09, 2020, 08:08:54 PM
Thank you. I'm a bit further. Since I'm working in the stencil, it looks like my only option is the Master Explorer. The others options are grayed out. In the tree view for Masters, I see the following:

Masters
  MyShapeName
    Class.34
      Shapes
        Sheet.10
        Sheet.6
        Sheet.7
        Sheet.9

There is no Sheet 5 in the tree but yet it is being referenced in a formula on Sheet.10. With nothing selected on the shape, I then right click it and selected Show ShapeSheet. This opens up the shape sheet titled xxx.vss:Stencil:MyShapeName.Class.34.

I determined that Class.34 is sheet 5. What I did was create a user defined cell called Test set to ="Hello" on Class.34 shape sheet and referenced it in another user defined cell on the shape  sheet for sheet 10 using =Sheet.5!User.Test. Hello shows up as expected.

Seems strange that the tree node does not show Sheet.5 but instead Class.34.
Title: Re: How to Find a Shape with a Given ID?
Post by: Visio Guy on March 09, 2020, 09:37:33 PM
Hi A-Man,

I've written a little VBA procedure that might help you. To use it, do this:


After it runs, a red circle will appear in the page around the pin/rotation-point of your target shape.

You could add this code to a stencil, then save it as a .VSSM-type stencil in your Favorites. The VSSM file type allows you to run macros. You could then load the stencil any time you need the code.

Otherwise, just paste the code into any document and run it, but don't save it. :)



'// Note: this code works for an active window that is showing a drawing page or a
'// master editing window:
Public Sub HighlightShape()

  '// Place the cursor in this procedure
  '// Type F5
  '// Enter a (valid) ID number for a shape on the active page
  '//
  '// A red circle will be drawn around your shape!

  Dim id As Integer 
  id = InputBox("Enter sheet id:", "Highlight Shape", 5)
 
  '// Define a bunch of variables:
  Dim shpPg As Visio.Shape '//...the shape for the drawing page or master page
  Dim shp As Visio.Shape '//...the target shape we are looking for, "Sheet.id" so to speak.
  Dim shpHL As Visio.Shape '//...the "highlight shape" that we will draw
  Dim xPin As Double, yPin As Double, xPg As Double, yPg As Double, r As Double
 
  If Not (Visio.ActiveWindow.Page Is Nothing) Then
    Set shpPg = Visio.ActiveWindow.Page.PageSheet
  ElseIf Not (Visio.ActiveWindow.Master Is Nothing) Then
    Set shpPg = Visio.ActiveWindow.Master.PageSheet
  End If
 
  If (shpPg Is Nothing) Then
    Call MsgBox("Couldn't find an active page or master-page!")
    GoTo Cleanup
  End If
 
  Set shp = shpPg.Shapes.ItemFromID(id)
 
  '// Pick a radius based on the size of the target shape:
  r = (shp.CellsU("Width").ResultIU + shp.CellsU("Height").ResultIU) * 0.25
 
  '// Get the local location of the target shape's pin:
  xLocPin = shp.CellsU("LocPinX").ResultIU
  yLocPin = shp.CellsU("LocPinY").ResultIU
 
  '// Find the pin of the target shape, relative to the page:
  Call shp.TransformXYTo(shpPg, xLocPin, yLocPin, xPg, yPg)
   
  Set shpHL = shpPg.DrawOval(xPg - r, yPg - r, xPg + r, yPg + r)
  shpHL.CellsU("Geometry1.NoFill").FormulaForceU = "TRUE"
  shpHL.CellsU("LineColor").FormulaForceU = "RGB(255,0,0)"
  shpHL.CellsU("LineWeight").FormulaForceU = "3pt"
 

Cleanup:
  Set shpHL = Nothing
  Set shp = Nothing
  Set pg = Nothing
End Sub
Title: Re: How to Find a Shape with a Given ID?
Post by: analogman on March 11, 2020, 06:04:22 PM
Thanks Visio guy! I tried this out and it is rather interesting. Unfortunately, I'm not sure which shape I was having an issue with. I tried a few shapes that I was working on a couple days ago and they aren't exhibiting the same problem. I wonder if it was a quirk with Visio. In any case, I'll be sure to try this if it happens again.

Thanks for taking the time to put this together.

Analogman