Dynamic Connectors

J

Jonathan Spane

I am currently writing an Add-On in C++, and I am having some confusion with
dynamic connectors.

I have a Visio Drawing in which two rectangle shapes are connected by a
dynamic connector. This shape was created manually through the Visio GUI.

Ex:
------- ------
| A |-------C---->| B |
------- ------

* the C connector starts at A and ends at B.

My add-on grabs all the shapes in the page and for each rectangle shape I am
trying to determine which other rectangles it connects to via the connector.
More importantly since the dynamic connector is the shape of an arrow I
really need to see which shape connects to the end(arrow part) of the
connector.

I am using the FromConnects properties of the rectangle shapes which says
there is connector connected to shape A.

If I do the same logic for shape B it shows me that there is connection
shape C connected to B.

If I do the same logic for the connection shape C it shows that there are
two connections shape A and B but it makes to difference between which one
it starts at and which one ends at.

I have read the following help section:
http://msdn2.microsoft.com/en-us/library/aa201774(office.10).aspx

After reading, the first half confirms what I am seeing. The second half
contradicts what I am seeing, but the second half example deals with shapes
connected programmatically instead through a user using the Visio GUI.

Is there something I am missing?

The task at hand is the following:
How can I tell that shape A is connected to shape B with a one way
connection arrow?

Thanks for any help
JP
 
J

JuneTheSecond

I don'know this may be a help for you.
I'd mede a function to detect a shape that connects to end point of
1-dimensional shape.

Private Function ShapeAtEndPoint(line As Visio.Shape) As Visio.Shape
Dim cs As Visio.Connects, c As Visio.Connect
Dim shp As Visio.Shape
Set cs = line.Connects
For Each c In cs
If c.FromPart = visEnd Then
Set shp = c.ToSheet
Set ShapeAtEndPoint = shp
End If
Next
End Function
 
J

Jonathan Spane

Thanks for that. It was the the GetPart that I was missing. Here is a c++
version for those that are interested. I am using the visiwrap class which
makes life easier.

HRESULT
GetShapeAtEndPoint(CVisioShape& connectionShape,
CVisioShape& endShape)
{
HRESULT hResult = -1;

if(!connectionShape.IsSet()) return hResult;

//Get all the connections to the shape.
CVisioConnects visioConnects;

if(SUCCEEDED(connectionShape.Connects(visioConnects)))
{
//get the number of connections and loop over them
long connectCount = 0;
visioConnects.Count(&connectCount);

//array is 1 based
CVisioConnect visioConnect;
short fromPart = 0;
for(long conIndex=1; conIndex<=connectCount; conIndex++)
{
//For each connected shape get its from part
if(SUCCEEDED(visioConnects.Item(conIndex, visioConnect)))
{

if(SUCCEEDED(visioConnect.FromPart(&fromPart)))
{
if(visEnd == fromPart)
{
//This connected shape is attached to the end
hResult = visioConnect.ToSheet(endShape);
break;
}
}
}
} //end for loop

//just to be safe
if(SUCCEEDED(hResult))
{
//invalid shape somehow
if(!endShape.IsSet())
{
hResult = -1;
}
}
}
return hResult;
}
 

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