Author Topic: Possible to "jump" to certain shapesheet?  (Read 6515 times)

0 Members and 1 Guest are viewing this topic.

Michelle

  • Full Member
  • ***
  • Posts: 151
Possible to "jump" to certain shapesheet?
« on: March 24, 2011, 11:06:04 AM »
I have a large Visio drawing that has many many shapes in a template.  In making changes to one shape, often many of the others are affected.  When I go into these other shapes to make changes, sometimes I discover that I actually need to go into ANOTHER shape because that other shape is referenced.  For example, I change the wall thickness of my main shape... so i also need to change the thickeness of all the windows in that shape.  So I go into window "a" only to find out that the thickness actually references another of the windows.  The Width cell says something like: "Sheet 325!Width". 

Is there a way to easily find or jump to Sheet 325?  Without having to scroll thru the many shapes in my drawing explorer?  (Some of the shapes in here have been re-named by me anyways so they may or may not even reference the #325...Ugh!)

I hope I am making sense!  Thanks in advance...
Michelle

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3936
  • Ideas Visio-lized into solutions
Re: Possible to "jump" to certain shapesheet?
« Reply #1 on: March 24, 2011, 11:10:54 AM »
My guess would be that you need a small macro that allows you to enter shapename and ID, which would then select and zoom to that shape.

Wapperdude
Visio 2019 Pro

Michelle

  • Full Member
  • ***
  • Posts: 151
Re: Possible to "jump" to certain shapesheet?
« Reply #2 on: March 24, 2011, 12:31:35 PM »
I've never done a Macro before... any websites or books you can recommend with good tutorials or examples? (This sounds like it may be beyond my current capabilities.  :'()

Michelle

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Possible to "jump" to certain shapesheet?
« Reply #3 on: March 24, 2011, 02:32:39 PM »
Another idea could be the drawing explorer. You find it in the menu "View". In an explorer like structure you can see here listed all the shapes by name.

If that doesn't help I'll provide a macro, but can only do tomorrow as it is time to go to bed in Germany now  :)

Michelle

  • Full Member
  • ***
  • Posts: 151
Re: Possible to "jump" to certain shapesheet?
« Reply #4 on: March 24, 2011, 02:49:26 PM »
I have been using the drawing explorer, but it's not perfect.  Many of the shapes have been renamed, so the drawing explorer does not list the sheet with it's number the same as it shows up in the shapesheet.  I was just hoping for a timesaver! 

If you could help out with a macro, I'd appreciate it.  Hopefully (maybe) I can learn something from it too (by looking in at the code).  ;D

Thanks!
Michelle

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Possible to "jump" to certain shapesheet?
« Reply #5 on: March 24, 2011, 03:15:32 PM »
OK, so you don't have to wait all night:

Press Alt+F11 to open the VBA-Editor.  Copy the code below in the code-window (of the ThisDocument modul).
Press Save Button. Close VBA-Editor. In Visio Main Window. Goto Extras-Macro-ThisDocument-
and choose either SearchNameID or SearchNameU.
You'll be prompted to enter the shapename (Casesensitive!).

Code
Sub SearchNameID()
Dim shp As Visio.Shape
Dim s As String

s = InputBox("Enter ShapeName+ID like Sheet.123")

ActiveWindow.DeselectAll
For Each shp In ActivePage.Shapes

  If shp.NameID = s Then
    ActiveWindow.Select shp, visSelect
    Exit Sub
  End If
Next

MsgBox "Shape not found"

End Sub


Sub SearchNameU()
Dim shp As Visio.Shape
Dim s As String

s = InputBox("Enter ShapeNameU like MyShapesName")

ActiveWindow.DeselectAll
For Each shp In ActivePage.Shapes

  If shp.NameU = s Then
    ActiveWindow.Select shp, visSelect
    Exit Sub
  End If
Next

MsgBox "Shape not found"

End Sub

So and now off to bed. Maybe grandfather will tell me a story...

Michelle

  • Full Member
  • ***
  • Posts: 151
Re: Possible to "jump" to certain shapesheet?
« Reply #6 on: March 25, 2011, 09:31:17 AM »
Thanks Jumpy!  I appreciate your help, I just hope you can be patient with me!  :-[

Let me ask some questions to see if I am doing something wrong, or if my template is just too complicated (i.e. unorganized) to allow the code to work.  I keep getting "Shape not found" results.

If I have a shape within a shape (within another shape, etc) can this code drill in to find it?  Or does it all need to be on the same level? 

If I go to Format --> Special, many of my shapes have names something like this: "ShapeName.150".  The ID of this shape is usually NOT 150... it might be 66.  When originally creating this template, I named many of my shapes descripively so I knew what they were, and I added the .150 at the end of the shape name so I could tell what the shape ID was without having to go into Format Special to look it up.  However it seems that in my many edit/save sessions, the IDs have changed?  Because most of them do not seem to match up with the shape name like I originally intended. 

If I am to search for the above example, do I enter ShapeName.150 or ShapeName.66?  And in general, what is the difference between choosing SearchNameID, and SearchNameU?  Also I notice that I can also choose these macros in Tools --> Macro--> Module1.  What is Module1?

Thanks so much for your patience!

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Possible to "jump" to certain shapesheet?
« Reply #7 on: March 25, 2011, 09:52:47 AM »
In Backward Order:

Modul1 is the Name of the VBA Modul where you copied the code. In the VBA-Editor you can have many moduls where you can store VBA-code. The moduls belong to the drawing and a saved with it. Every drawing has a modul called "ThisDocument" that is the standard modul. You can (and probably have) add(ed) a new modul. Moduls added get name like Modul1, Modul2,... The names can be changend later.

NB: In Extras-Macros you can assign Short-Cuts to the macros to make it more easy to start them.

-----------

Now it gets complicated: The names in Visio!
A shape has
a Name,
a NameU (U = Universal Name)
a NameID (Sheet.123  ->  The word Sheet, followed by "." followed by the ID-number)
an ID (The ID number like 123)
an Indexnumber (Different from the ID, its the number of the Shape in the Shapes-Collection of the page, the Shape is on).

If you take a simple shape from a stencil, say the Box-Shape (Rectangle), and drag it on the page it gets:
Name: Box
NameU: Box
NameID: Sheet.5 (number is only an example)
ID: 5

Now you drag another Box-shape on the page. Because names must be unique Visio gives the following names:
Name: Box.7 (number is only an example)
NameU: Box.7
NameID: Sheet.7
ID: 7

Now you rename that second shape to "MyBox" / or like you did to "MyBox.7"
Name: MyBox   /MyBox.7
NameU: MyBox /MyBox.7
NameID: Sheet.7
ID: 7

Now different things can happen. First example you change the name a secon time, e.g. to "MyNewShapename". Look what happens to NameU.
Name: MyNewShapename
NameU: MyBox
NameID: Sheet.7
ID: 7
Nothing happens to NameU, only the first renaming changes Name and NameU. Every additional renaming only changes Name.
!!!But: Only NameU (or NameID) can now be used for reference in ShapeSheet, so you see a name in ShapeSheet and search for the shape, but you don't find it, beause you look for the Name, but the Name is not the same as NameU anymore!

Therefore the NameU macro searches for the NameU as that is the name in the ShapeSheet.
In case the reference in the ShapeSheet is with the NameID (e.g. Sheet.123) the other macro searches for the shapes via NameID.


Another thing that can happen, is that Visio changes the ID (like you mentioned):
Name: MyBox   /MyBox.7
NameU: MyBox /MyBox.7
NameID: Sheet.325
ID: 325

----------

I mentioned above, that names must be unique. That was not quite correct. They must be unique for all shapes and groups on the page. But sub-shapes inside a grouped shape must only be unique inside that group (if I recall correctly). That means a subshape in group 1 can eventually have the same name as a subshape in group 2.
It may be, that the NameID must be unique nevertheless, but I'm nut sure about that.

----------

To drill down into the groups a little change to the code is needed, added a search for just the ID, too. Maybe it helps.
If you want to search for Name, too, it should be easy for you add a fourth code section in copiing the NameU code and deleting the U everywhere ;-)
Code
'*****************************************************
'Search for NameID:

Sub SearchNameID()
  Dim shp As Visio.Shape, Dim s As String

  s = InputBox("Enter ShapeName+ID like Sheet.123")
  ActiveWindow.DeselectAll

  For Each shp In ActivePage.Shapes
     SNID(shp,s)  
  Next

  If ActiveWindow.Selection.Count = 0 then MSGBOX("No Shape found")

End Sub

Sub SNID(shp as Shape, s as String)
Dim Subshp as Shape
  If shp.NameID = s Then
    ActiveWindow.Select shp, visSelect
  End If

  For Each subshp in shp.Shapes
    SNID(subshp,s)  
  Next
End Sub

'*****************************************************
'Search for NameU:

Sub SearchNameU()
  Dim shp As Visio.Shape, Dim s As String
  s = InputBox("Enter ShapeNameU like MyShapesName")
  ActiveWindow.DeselectAll
  For Each shp In ActivePage.Shapes
    SNU(shp,s)  
  Next
  If ActiveWindow.Selection.Count = 0 then MSGBOX("No Shape found")
End Sub


Sub SNU(shp as Shape, s as String)
Dim Subshp as Shape
  If shp.NameU = s Then
    ActiveWindow.Select shp, visSelect
  End If

  For Each subshp in shp.Shapes
    SNU(subshp,s)  
  Next
End Sub

'*****************************************************
'Search for ID only:

Sub SearchID()
  Dim shp As Visio.Shape, Dim s As String

  s = InputBox("Enter ID like 123")
  ActiveWindow.DeselectAll

  For Each shp In ActivePage.Shapes
     SID(shp,s)  
  Next

  If ActiveWindow.Selection.Count = 0 then MSGBOX("No Shape found")

End Sub

Sub SID(shp as Shape, s as String)
Dim Subshp as Shape
  If shp.ID = s Then
    ActiveWindow.Select shp, visSelect
  End If

  For Each subshp in shp.Shapes
    SNID(subshp,s)  
  Next
End Sub

hth Jumpy
« Last Edit: March 28, 2011, 03:36:56 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1721
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Possible to "jump" to certain shapesheet?
« Reply #8 on: March 28, 2011, 03:37:27 AM »
Nice analysis, Jumpy. I might just cut and paste that into an article over on visguy.com :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Possible to "jump" to certain shapesheet?
« Reply #9 on: March 28, 2011, 05:32:51 AM »
Hi Chris,

feel free to do so, but give it some polish first, because I'm not always sure of my english.
Also I'm not 100% sure, if all the facts a right, especially the part with names in Groups.

Thanks for the praise,

Jumpy