Share via


Working with a Connect Object

A Microsoft® Visio® shape can be connected or glued to another Visio shape in a drawing. In the Visio object model, this relationship is represented by a Connect object. A Connect object represents a connection between two shapes in a drawing, such as a line and a box in an organization chart.

Connect object and related objects higher in the Visio object model

Connect object and related objects higher in the Visio object model

Once you get a reference to a Connect object, you can find out which shapes are connected and how they are connected. You can also analyze directed graphs, such as flowcharts, or connected diagrams, such as organization charts, by getting properties of Connect objects for Shape, Master, and Page objects.

The Connects property of a Page object returns a Connects collection that includes a Connect object for every connection on the page. The Connects property of a Master object returns a Connects collection that includes a Connect object for every connection in the master.

A Shape object has two connection-related properties:

  • A Connects property, which returns a Connects collection that includes a Connect object for each shape, group, or guide that shape is glued to.
  • A FromConnects property, which returns a Connects collection that includes a Connect object for each shape, group, or guide glued to that shape.

For example, suppose a drawing contains two shapes named A and B and a one-dimensional (1-D) shape named C that connects A and B.

Two shapes connected by a 1-D shape

Two shapes connected by a 1-D shape

  1. The Connects collection for A's Connects property is empty. The Connects collection for A's FromConnects property contains one Connect object that represents A's connection from C. A is not glued to any shape (Connects property), but C is glued to A (FromConnects property).
  1. The Connects collection for B's Connects property is empty. The Connects collection for B's FromConnects property contains one Connect object that represents B's connection from C. B is not glued to any shape (Connects property), but C is glued to B (FromConnects property).
  1. The Connects collection for C's Connects property contains two Connect objects: one representing C's connection to A, and the other representing C's connection to B. The Connects collection for C's FromConnects property is empty. C is glued to A and B (Connects property), but no shape is glued to C (FromConnects property).

Or suppose a drawing contains four shapes named A, B, C, and D. Each shape has a control handle that is glued to a shape named E. In this case, shapes A, B, C, and D are connected to E directly via the control handle; the lines that show a hierarchical relationship between the shapes in this example are being drawn programmatically after the control handle is glued.

Four shapes glued to one shape in a drawing

The Connects collection of E is empty, because it is not glued to A, B, C, and D—they are glued to E. The Connects collections of A, B, C, and D each contain one Connect object.

To get the Connects collection of shape A, get the Connects property of that Shape object. For example:

Set consObj = shpObj.Connects

The Connects collection of shape A contains one Connect object that represents A's connection to E. This is also true of the Connects collections of shapes B, C, and D. The Connects collection of shape E is empty, because it's not glued to the other shapes—they are glued to it.

Summary of properties for determining connections

Object

Property

Returns

Shape, Page, or Master

Connects

A Connects collection that includes a Connect object for each shape that shape is glued to.

Shape

FromConnects

A Connects collection that includes a Connect object for each shape glued to that shape.

Connects collection or Connect object

FromSheet

The shape a connection or multiple connections originate from (the shape or shapes creating the connection).

Connects collection or Connect object

ToSheet

The shape one connection or multiple connections are made to (the shape or shapes receiving the connection).

Connect object

FromPart

The part of a shape a connection originates from (the part of the shape that creates the connection).

Connect object

ToPart

The part of a shape a connection is made to (the part of the shape that receives the connection).

Connect object

FromCell

The cell of a shape a connection originates from (the cell in the shape that creates the connection).

Connect object

ToCell

The cell of a shape a connection is made to (the cell in the shape that receives the connection).