There are a few nuances to this. For example, you are assuming that
myTransition can only connect two shapes, an assumption which I don't
believe is generally true (theoretically, I think you could have a one-to-n
or n-to-n connector).
The key is in understanding the Visio object model's Connect object. A
Connect object represents a connection between two shapes, such as between
the endpoint of a connector and a connection point it's connecting to
(there's a terminology issue here: there are connects, connectors, and
connection points, and they're all different!).
Shapes and pages both maintain a Connects collection. What you probably
want to do is iterate through your Shapes collection, and for each shape
interrogate its Connects collection. Check each Connects object's FromSheet
property. If the result is the shape itself, then that shape is gluing TO
something else. Get that "something else" using the Connect's ToSheet
property.
In your example below, Shape1 and Shape3 would both have one Connect object,
and in both cases the FromSheet property would produce the myTransition
shape. So your method would ignore these (since the FromSheet is not the
shape itself). myTransition would have two Connects objects, and in each
case it would be in the Connect's FromSheet property. One of the Connects
would have Shape1 as the ToSheet and the other would have Shape3.
If the connection is undirected, just make whichever ToSheet you get first
as the From shape. If direction matters, I believe you need to check the
Connect's FromCell to see whether it's BeginX or EndX. This tells you which
endpoint of the Transition shape that particular connection is on.