Mass Selecting Connectors

  • Thread starter vespasiandamascus
  • Start date
V

vespasiandamascus

I am currently working on a very large, nearly-complete organizational
chart. I am at a stage where I am trying to write a few macros to make
reading and referring to the chart a little easier, and I'm stuck at a
one concept in particular.

My goal is to create a macro that can do the the following task: Upon
selecting a certain shape, it will hide every connector, except those
that connect directly to the selected shape. This will and make it
much easier to read.

I have created this exact macro before, for a smaller project, but
that was when all lines connecting to a certain shape were stored in a
distinctive layer... this macro was very simple to create, and I have
no problems doing just that, the only drawback is that every connector
(over 250 in total) are all stored in a single layer and it would be
next to impossible to sort them out at this point.

-----

My question is: Is there a built-in Visio tool that can select all
connectors that connect to a given shape? If not, can anyone suggest
an alternate method in helping me complete this macro?

I have looked online and throughout my visio references (Microsoft
2003 Developer's Survival Pack, Developing Visio Solutions for
Microsoft 2000) and haven't come across anything that corresponds to
the problem I am having.
Any help would be greatly appreciated! Much thanks in advance,

Damascus
 
V

vespasiandamascus

EDIT: I believe a method for finding the ItemID's of all connectors
would also work!
 
V

vespasiandamascus

Thanks for the quick response! I think we are on the right track.

I have tried writing the following macro, based on your first site
example:

Sub ConnectsCollection1()
objRet = Application.ActiveWindow.Page.Shapes.ItemFromID
(419).FromConnects
End Sub

....where "Application.ActiveWindow.Page.Shapes.ItemFromID(419)" is the
name of the specific shape that I am trying to find the connects for.
I am getting the following error:
Run-time error '450':
Wrong number of arguments or invalid property assignment.

Do you have any ideas? Just so you know, I am unable to install the
SDK due to security purposes on my work machine... if you we can't
debug this sub procedure, do you think it would be possible for you to
copy and paste the code from David Parker's answer (from the SDK)

Once again, thank you very much.

Damascus
 
W

WapperDude

Here's a copy of code from
http://msdn.microsoft.com/en-us/library/ms426567.aspx

It give you a good start.

Public Sub ToSheet_Example()

Dim vsoShapes As Visio.Shapes
Dim vsoShape As Visio.Shape
Dim vsoConnectTo As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect
Dim intCurrentShapeIndex As Integer
Dim intCounter As Integer
Set vsoShapes = ActivePage.Shapes

'For each shape on the page, get its connections.
For intCurrentShapeIndex = 1 To vsoShapes.Count

Set vsoShape = vsoShapes(intCurrentShapeIndex)
Set vsoConnects = vsoShape.Connects

'For each connection, get the shape it connects to.
For intCounter = 1 To vsoConnects.Count

Set vsoConnect = vsoConnects(intCounter)
Set vsoConnectTo = vsoConnect.ToSheet

'Print the name of the shape the
'Connect object connects to.
Debug.Print vsoConnectTo.Name

Next intCounter

Next intCurrentShapeIndex

End Sub
 
V

vespasiandamascus

Thanks!... I think this is the right method. I realize that in order
for that piece of sample code to actually do anything in my project, I
have to alter it to accommodate the changes in shape names etc..

I ran it first without changes and I got no error message, but nothing
happened either (as predicted). I tried changing:
Set vsoShapes = ActivePage.Shapes
to:
Set vsoShapes = Application.ActiveWindow.Page.Shapes
, which I am pretty sure is the name of the location of all shapes.
Still, nothing happened. Would you happen to know exactly what changes
I need to make?

Thank you so much, you're being very helpful and I really appreciate
it!
 
W

WapperDude

This code only prints the results in the "Immediate" sub-window of the Visio
Basic Editor window. (There's probably a better technical term for all of
that.) One way to get to it is menu bar > Tools > Macros > Visual Basic
Editor. Then run the macro in debug mode.

You can use the "ActivePage" since, by default, it is open. Using the
"ActiveDocument...." is more complete, but not really necessary.

The statement "Debug.Print" is what pushes the results into the "Immendiate"
window. It's at that point in the code where you need to collect your
results in an array, or userform, or act upon each shape individually as it
comes up...depending upon what you want to do with the results.
 
V

vespasiandamascus

Yeah, I understand that results are supposed to show in the VBE
window... but still, nothing is happening. How exactly can I be sure I
am running the procedure in Debug Mode? I turned off Design Mode.

Also, My undo function is disabled for some reason. I have searched
for similar problems and the general consensus is that I have to type
the following into my VBE:
Visio.Application.UndoEnabled = True
and hit enter. I did this, and still nothing happens. I think I am
doing something wrong as far as running the actual macros. Any ideas?

Thanks again (and again and again)

Damascus
 
W

WapperDude

First things first,
1) Is the Immediate window showing in the VBE window? If not, menu bar >
View > Immediate window.

2) Debug is one of the Entries on the Menu bar. Or, you can just put the
cursor at the beginning of the sub-routine, and repeatedly press F8 to step
thru the macro. Each time a line executes, you can hover the cursor over the
variable and see it's value. There are other techniques which are explained
in previous references.

3.) The shape ID in question is "419". This routine assumes that the
shapes are numbered sequentially, beginning at "1". If for some reason, the
actual ID's begin at a number higher than the shape count, there won't be any
results. This strikes me as unlikely though.

4.) You could modify (eliminate) the outer loop, and just hard code for the
419 shape of interest.

HTH
Wapperdude
 
V

vespasiandamascus

Quick question: Now that it is showing me something in the immediate
window, how can I directly work with the results? The immediate window
is saying something like 'Rounded rectangle.23' or 'Sheet.599'. I
can't use this syntax when working wiith the shapes, it requires
syntax like: Application.ActiveWindow.Page.Shapes.ItemFromID(1). I
tried just substituting vsoConnectTo.Name, but it is giving me an
error message.

Basically, I want to create a temporary layer that contains all the
ConnectTo's and ConnectFrom's. As the sub procedure goes through each
Connect, I will add it to the layer. I think I am almost there now, I
just need the proper syntax (I am new to visual basic but I have a
fair bit of experience in other languages... the logic is not a
problem).

If you know the answer off the top of your head that would be awesome,
if not don't worry about you have helped immensely already.

Thank you

Damascus
 
W

WapperDude

The Immediate window was intended to confirm that the program does what is
desired. Now you need to replace the debug.print line with additional lines
of code. A couple things to consider would be:
1.) As each shape is found, assign to a temporary variable, then, assign it
to your layer.
2.) Add each shape to a collection, then assign the collection to the layer
3.) Add each shape to a group, then to a layer, but I think this might not
work properly.

HTH
Wapperdude
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top