Author Topic: How to Identify the Shapes Connected by a Specific Connector  (Read 15031 times)

0 Members and 1 Guest are viewing this topic.

joules

  • Jr. Member
  • **
  • Posts: 11
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??
« Last Edit: May 23, 2008, 08:41:28 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1669
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: How to Identify the Shapes Connected by a Specific Connector
« Reply #1 on: May 23, 2008, 08:40:53 AM »
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#!)

« Last Edit: May 23, 2008, 09:28:58 AM by Visio Guy »
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

  • Sr. Member
  • ****
  • Posts: 278
Re: How to Identify the Shapes Connected by a Specific Connector
« Reply #2 on: May 23, 2008, 08:51:06 AM »
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

  • Jr. Member
  • **
  • Posts: 11
Re: How to Identify the Shapes Connected by a Specific Connector
« Reply #3 on: May 26, 2008, 02: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.

Code: [Select]

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);
    }
  }
}
« Last Edit: May 26, 2008, 07:43:58 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1669
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: How to Identify the Shapes Connected by a Specific Connector
« Reply #4 on: May 26, 2008, 07:47:34 AM »
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

  • Newbie
  • *
  • Posts: 2
Re: How to Identify the Shapes Connected by a Specific Connector
« Reply #5 on: February 10, 2015, 10:36:44 PM »
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
« Last Edit: February 11, 2015, 04:27:43 AM by Paul Herber »