How to Identify the Shapes Connected by a Specific Connector

Started by joules, May 23, 2008, 12:01:38 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

joules

Hi.I'm new to working with visio control in c#.net.In my application i need to identify the shapes connected by a given connector.Also when i select a shape i need to know to which shape its connected.Can anyone suggest how to do this??

Visio Guy

Hi Joules,

It's not super straight-forward, but it's not rocket science, thankfully. You just need a few hints to get going in the right direction.

The info you need is buried in the conference materials from my presentation at the 2008 Visio Conference. See the post: Visio Solution Developer Pain Points Presentation and download the stuff.

Determining connections is on my article-TODO list, to make it more accessible to all, but I haven't gotten round to it.

Also, here's some quick tips, maybe all you need to get going:


  • A connector will have a Connects collection
  • If it's glued at both ends, there will be two Connect objects in this collection
  • Examine the ToSheet property of each Connect object to see to which shape the connector is glued
  • Examine the FromCell property of each Connect object to see from which end of the connector the Connect object comes
  • Now that you understand the Connect object, select a connected-to shape (ie: a box), and examine it's FromConnects collection. This is simply the other side of a connector's Connects collection.
  • With these tips and terms in mind, download the "Visio 2007 SDK" and check out the handy-dandy Code Samples Library and look for a sample to save you time (samples in VB, VB.NET and C#!)

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Lars-Erik

I'm positive I've seen some C for this, I was looking to do this using VBA, and all I could find was C code, now i need C and I cant find it anymore... I'll look around some more. There's some sample code out there I'm positive!

joules

hi,

Thanks for the help. I'm just posting a sample code here so that people can refer if needed  :)

In the code , for each connector I've displayed the shapes that are glued to that connector.



Visio.Connects visconnects;
Visio.Shape visshape;
Visio.Shape toshape;
Visio.Connect visconnect;
         
Visio.Page currentPage = axDrawingControl1.Document.Pages[1];

Visio.Shapes shs = currentPage.Shapes;
for (int i = 1; i <= shs.Count; i++)
{

  visshape = shs[i];

  //Only if the shape is a connector
  if (visshape.LineStyle == "Connector")
  {
    visconnects = visshape.Connects;
    MessageBox.Show("Connector : " + visshape.Name);
               
    for (int k = 1; k <= visconnects.Count; k++)
    {
      visconnect = visconnects[k];
      toshape = visconnect.ToSheet;
      MessageBox.Show(toshape.Name);
    }
  }
}

Visio Guy

Thanks joules!

There's another quick check that helps in connector chasing:

If(shp.OneD = 0)....

Visio shapes are either 1D or 2D. Connectors are 1D, boxes are 2D. A lot of times, when analyzing connectors, it helps to look for all the 2D shapes, or all the 1D shapes, depending on which way you are going about it.

Cheers,

- Chris
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

andyadams

#5
I recently do my work with issn barcode and i need to make a diagram contain barcode using c#.I am creating a visio diagram but need to check if existing shapes are connected. I wrote a method with 3 different ways to determine this. I couldn't find any shapes methods to do this directly. Here's what I came up with. I am preferable to the 3rd method because it doesn't involve iteration. Any more suggestions