Visio Guy

Visio Discussions => Programming & Code => Topic started by: morelup on May 20, 2019, 08:18:50 PM

Title: Help determining which shapes are glued to which connector points
Post by: morelup on May 20, 2019, 08:18:50 PM
I have shapes that have multiple outgoing connector points.  These connector would have a 1 to many relation.  So:
I have shape 1, which is connected to shape 2/3/4 from connection points 2/3/4.

I can easily get the list of shapes connected to 1 using the ConnectedShapes method.  I can also get the connectors by using GluedShapes on shape 1.

Right now if i want to find out which connector is being used between shapes 1 and 2, i have to loop through each of the glued shapes, look at where the start pin is using for its refernce on shape 1, and find the name of that connector.  Is there an easier way of going about this?
Title: Re: Help determining which shapes are glued to which connector points
Post by: morelup on May 21, 2019, 07:04:47 PM
I ended up doing:

List<int> connectors = new List<int>((int[])v._shape.GluedShapes(Microsoft.Office.Interop.Visio.VisGluedShapesFlags.visGluedShapesOutgoing1D, ""));
                     string startLocation = "";
                    foreach (int connector in connectors)
                    {
                        Shape tempConnector = v._parent._page.Shapes.ItemFromID[connector];
                        int j = 0;
                        string tempLocation = "";
                        bool found = false;
                        foreach(Connect test123 in tempConnector.Connects)
                        {
                            if (j == 0)
                            {
                                tempLocation = new Regex("Connections.(.*).X").Match(test123.FromCell.Formula).Groups[1].Value;
                                j++;
                            }
                            if (j==1 && l_vPath[i + 1]._shape == test123.ToSheet)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (found)
                        {
                            startLocation = tempLocation;
                            break;
                        }
                    }
Title: Re: Help determining which shapes are glued to which connector points
Post by: bwharrington on June 07, 2019, 08:37:02 PM
I have a similar situation. My needs may be different but what I do is inside of the connector, I store the two Shape IDs the connector knows about in the Shape Sheet in properties named FirstShapeId, SecondShapeId

You can access the shapes by looping/searching over the connectors, grabbing the First and Second Shape Ids and find the Shape you need. Using this has free'd up code and made my life a lot easier.