".Connects" member

V

vespasiandamascus

Hi everyone. I am trying to access the connects for a selection of
shapes. All my connectors are double-headed arrows, I'm not sure if
that makes a difference or not. Here is the code I am using:

Sub TestMac()

Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

For Each vsoShape In vsoSelect
Debug.Print vsoSelect.Count
Set vsoConnects = vsoShape.Connects
Debug.Print vsoConnects.Count
Next vsoShape

End Sub
-----
The vsoShape.Connects line is returning 0 every time.

If I use the FromConnects member instead of Connects, it returns the
correct number. I need to access the Connects however, as I need to
find the actual shapes that each shape in my selection connect to.

Does anyone know what I am missing?

Thanks in advance.
 
P

Paul Herber

Hi everyone. I am trying to access the connects for a selection of
shapes. All my connectors are double-headed arrows, I'm not sure if
that makes a difference or not. Here is the code I am using:

Sub TestMac()

Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

For Each vsoShape In vsoSelect
Debug.Print vsoSelect.Count
Set vsoConnects = vsoShape.Connects
Debug.Print vsoConnects.Count
Next vsoShape

End Sub
-----
The vsoShape.Connects line is returning 0 every time.

If I use the FromConnects member instead of Connects, it returns the
correct number. I need to access the Connects however, as I need to
find the actual shapes that each shape in my selection connect to.
Does anyone know what I am missing?

So, why not use the FromConnects instead, the count is right, you can
then iterate through the FromConnects.Items and look at the
connections to see where they go.
 
V

vespasiandamascus

So, why not use the FromConnects instead, the count is right, you can
then iterate through the FromConnects.Items and look at the
connections to see where they go.

--

Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio    http://www.electronics.sandrila.co.uk/- Hidequoted text -

- Show quoted text -

Going through the from connects collection is returning information on
the connectors themselves and the original shapes I have selected. I
have tried every iteration of FromSheet and ToSheet and I am getting
only the two things I mentioned (the connector and the original
shape). I was pretty sure the Connects member could help me get
information on the secondary shapes, as I can think of no solution
using FromConnects.
 
J

John... Visio MVP

This requires some abstract thinking. When we look a drawing of two shapes
with a connecting line, we see Shape A connected to Shape B. What Visio sees
is Shape A connected to a connector and the connector connected to Shape B.
So what you need to look at is the connection collections for the connecting
shape. Another key point is that there is directionality to the connection
collections.
The reference to the connector may be in Shape A's Connect collection, but
it's from collection is empty while it is the reverse for the connector.

There is a better explanation here.
http://msdn.microsoft.com/en-us/library/aa201774(office.10).aspx

John.. Visio MVP
So, why not use the FromConnects instead, the count is right, you can
then iterate through the FromConnects.Items and look at the
connections to see where they go.

--

Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio http://www.electronics.sandrila.co.uk/- Hide quoted
text -

- Show quoted text -

Going through the from connects collection is returning information on
the connectors themselves and the original shapes I have selected. I
have tried every iteration of FromSheet and ToSheet and I am getting
only the two things I mentioned (the connector and the original
shape). I was pretty sure the Connects member could help me get
information on the secondary shapes, as I can think of no solution
using FromConnects.
 
V

vespasiandamascus

Okay, that makes a lot of sense. What I got out of it was that the
shape won't have a connects collection, but the connector will. So I
need to access the connectors connects collection, through the ToSheet
property.

This is what I added to the code which made sense to me, but I am
getting a type mismatch.
-----
Set vsoShapeTo = vsoConnect.ToSheet.Connects
Debug.Print vsoShapeTo.Text
-----
Where vsoShapeTo is a Visio.Shape type. The website said that Connects
from ToSheet returns a single shape, but I am getting a 'type
mismatch' compilation error. Would you have any suggestions?

Thanks John.
 
J

John... Visio MVP

Okay, that makes a lot of sense. What I got out of it was that the
shape won't have a connects collection, but the connector will. So I
need to access the connectors connects collection, through the ToSheet
property.

This is what I added to the code which made sense to me, but I am
getting a type mismatch.
-----
Set vsoShapeTo = vsoConnect.ToSheet.Connects
Debug.Print vsoShapeTo.Text
-----
Where vsoShapeTo is a Visio.Shape type. The website said that Connects
from ToSheet returns a single shape, but I am getting a 'type
mismatch' compilation error. Would you have any suggestions?

Thanks John.


Each shape has two connection collections. The shapes that it connects to
and the shapes that connects to it. So you should be able to find the
relationship between both shapes by looking in both collections. Once you
find the first round of shapes, then you need to repeat the process for the
connector's connection collections.

John... Visio MVP
 
V

vespasiandamascus

Yes, I'm trying to access both collections. The FromSheet is working
alright but I am getting a type mismatch for the ToSheet
 
J

John... Visio MVP

Yes, I'm trying to access both collections. The FromSheet is working
alright but I am getting a type mismatch for the ToSheet


Post the code. ;-)

John... Visio MVP
 
V

vespasiandamascus

Public Sub Macro1()

Dim vsoConnect As Visio.Connect
Dim vsoConnects As Visio.Connects
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoShapes As Visio.Shapes
Dim vsoShapeTo As Visio.Shape
Dim intCounter As Integer

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

Debug.Print vsoSelect.Count
If vsoSelect.Count > 0 Then

For Each vsoShape In vsoSelect

Set vsoConnects = vsoShape.FromConnects

For Each vsoConnect In vsoConnects

Set vsoShapeTo = vsoConnects.ToSheet.Connects
Debug.Print vsoShape.Text; " connects with ";
vsoShapeTo.Text

Next vsoConnect

Next vsoShape
Else
MsgBox "You Must Have Something Selected"
End If

Close #1

End Sub
 
V

vespasiandamascus

Public Sub ImmediateNeighbours()

Dim vsoConnect As Visio.Connect
Dim vsoConnects As Visio.Connects
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoShapes As Visio.Shapes
Dim vsoShapeTo As Visio.Shape
Dim intCounter As Integer

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

Debug.Print vsoSelect.Count
If vsoSelect.Count > 0 Then

For Each vsoShape In vsoSelect

Set vsoConnects = vsoShape.FromConnects

For Each vsoConnect In vsoConnects

Set vsoShapeTo = vsoConnects.ToSheet.Connects
Debug.Print vsoShape.Text; " connects to ";
vsoShapeTo.Text

Next vsoConnect

Next vsoShape
Else
MsgBox "You Must Have Something Selected"
End If

Close #1

End Sub
 
P

Paul Herber

Public Sub ImmediateNeighbours()

Dim vsoConnect As Visio.Connect
Dim vsoConnects As Visio.Connects
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoShapes As Visio.Shapes
Dim vsoShapeTo As Visio.Shape
Dim intCounter As Integer

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

Debug.Print vsoSelect.Count
If vsoSelect.Count > 0 Then

For Each vsoShape In vsoSelect

Set vsoConnects = vsoShape.FromConnects

For Each vsoConnect In vsoConnects

Set vsoShapeTo = vsoConnects.ToSheet.Connects

Set vsoShapeTo = vsoConnect.ToSheet.Connects
 
V

vespasiandamascus

That was the first thing I tried. I have experimented with a ton of
iterations and I tried to post the original one I thought made sense
but I guess I made that typo.


vsoConnect.ToSheet.Connects gives the type mismatch.
 
J

John... Visio MVP

vsoConnect vs vsoConnects - one letter, big difference

I would tend to replace

with
For Each vsoConnect In vsoShape.FromConnects

John... Visio MVP
 
J

John... Visio MVP

Set vsoConnects = vsoShape.From Connects
For Each vsoConnect In vsoConnects


It is, but it has one less variable (that can be easily confused) to deal
with and dispose of.

The less clutter the easier it is to read what the code is doing. Some of
the examples on the Visio VBA page use the "For i = 1 to count" structure
and I should take some time and simplify it to "For Each" structures.

John... Visio MVP
 
V

vespasiandamascus

Ahh okay. I misunderstood you before, I thought you were proposing a
solution to the .Connects problem.

It's always a good idea to minimize the amount of code written out,
thank you.
 
B

Barb Way

I created a small drawing (two shapes connected by one connector) and ran
your sample against it. Actually, I updated it a little :
Sub TestMac()

Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper
Debug.Print vsoSelect.Count

For Each vsoShape In vsoSelect
Debug.Print vsoShape.Name
Set vsoConnects = vsoShape.Connects
Debug.Print vsoConnects.Count
Next vsoShape

End Sub

The key here is that the info for vsoSelect.Count doesn't change, so I
pulled it out of the loop through the selection. Then I added a line to
print the shape name. Here is the output that I get :

3
Dynamic connector
2
Decision
0
Process
0

This makes sense, as there are 3 objects in the selection. Then we see the
name of each item, followed by the count of connections. The Dynamic
Connector is the only connector on the page, so it is to only non-zero
number, and it should be 2, since it connects to two shapes.

If you want to play with a great example of the use of Connects versus
FromConnects, I suggest installing the SDK (if you haven't already) and
searching the Visio Code Samples Library for "Drawing Navigator Using
Connections". There are samples for VB, VB.Net, and C#, and it is a great
demonstration of these properties, and how to 'walk' a drawing using the
connections information :

"Description:
This sample drops a set of shapes that are connected to each other in a
hierarchical fashion on a page and then walks through each shape from a
starting shape, using the begin and end points of the Dynamic connectors."

You are on the right track - try my version of your sample code in a simple
drawing, to see if you observe similar results to mine. Then you can test
out the Navigator sample to explore further.


Barb Way
Product Support - Visio
Microsoft Corporation
[This posting is provided "As Is" with no warranties, and confers no
rights.]
--------------------
Sub TestMac()

Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoConnects As Visio.Connects
Dim vsoConnect As Visio.Connect

Set vsoSelect = Visio.ActiveWindow.Selection
vsoSelect.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper

For Each vsoShape In vsoSelect
Debug.Print vsoSelect.Count
Set vsoConnects = vsoShape.Connects
Debug.Print vsoConnects.Count
Next vsoShape

End Sub
-----
The vsoShape.Connects line is returning 0 every time.

If I use the FromConnects member instead of Connects, it returns the
correct number. I need to access the Connects however, as I need to
find the actual shapes that each shape in my selection connect to.

Does anyone know what I am missing?

Thanks in advance.
 

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