Visio Guy

Visio Discussions => Programming & Code => Topic started by: joules on May 23, 2008, 12:01:38 PM

Title: How to Identify the Shapes Connected by a Specific Connector
Post by: joules on May 23, 2008, 12:01:38 PM
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??
Title: Re: How to Identify the Shapes Connected by a Specific Connector
Post by: Visio Guy on May 23, 2008, 01:40:53 PM
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 (http://www.visguy.com/2008/02/06/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:


Title: Re: How to Identify the Shapes Connected by a Specific Connector
Post by: Lars-Erik on May 23, 2008, 01:51:06 PM
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!
Title: Re: How to Identify the Shapes Connected by a Specific Connector
Post by: joules on May 26, 2008, 07:44:32 AM
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);
    }
  }
}
Title: Re: How to Identify the Shapes Connected by a Specific Connector
Post by: Visio Guy on May 26, 2008, 12:47:34 PM
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
Title: Re: How to Identify the Shapes Connected by a Specific Connector
Post by: andyadams on February 11, 2015, 03:36:44 AM
I recently do my work with issn barcode (http://www.keepautomation.com/products/net_barcode/barcodes/issn.html) and i need to make a diagram contain barcode using c# (http://www.keepautomation.com/how_to/csharp/).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