How to Find a Shape with a Given ID?

Started by analogman, March 09, 2020, 04:01:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

analogman

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

wapperdude

#1
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
Visio 2019 Pro

analogman

#2
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.

Visio Guy

#3
Hi A-Man,

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


  • Press F11 to bring up the VBA editor
  • Double-click ThisDocument in the Project Explorer window, which is usually docked on the left
  • Paste the code below into the code window
  • Place your cursor in the code procedure
  • Hit F5 to run
  • An input box will ask you for a Sheet.ID - just enter the number, not the "sheet" part

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
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

analogman

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