Dynamic Connector

N

nithya.176

Hi Guys,

Just wanted to know somethin. Is it possible to know which shape is
attached to either side of the dynamic connector programatically?
The scenario is I drag and drop shapes on the canvas and connect them
manually using the dynamic connector. Now i want to get the name of
the shapes that are on either side of the connector. How do i do
that.
If the answer is use the Fromshapes property. I tired but not sure how
exactly to do that. Can someone help me with a sample code? Plz..

Thanks,
Nithya
 
D

David Parker

The Visio SDK Code Samples Library contains Page Connections sample should
explain it
 
J

Jonathan Spane

Here is how you do it in C++. Good luck. Te key is to use FromPart method
of connection shape.

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

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 loo

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

return hResult;
}
 
N

nithya.176

Here is how you do it in C++. Good luck. Te key is to use FromPart method
of connection shape.

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

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 loo

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

return hResult;}

Hey Thanks a lot Jonathan. Will try converting the same code into C#
and let u know if it worked :)
 
N

nithya.176

The Visio SDK Code Samples Library contains Page Connections sample should
explain it

David i had another doubt wit the Page connection sample.
For running this sample I am opening a default .vsd diagram which has
some 3 shapes connected using a dynamic connector. And I am selecting
all the shapes using application.activeWindow.SelectAll();

But when i run the code the pageToWalk variable is null. Am i missing
somethin here?

if (pageToWalk == null)
{
return;
}
 
N

nithya.176

Ok i got it working now... :)
jus had to add this line

pageToWalk = applicationObj.ActivePage;

Thanks again guys...
chao
 

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