Working with Shapes Gluing

Get the Connectors Glued to a Particular Shape

Add and Connect Visio Shapes explains how to add a shape and connect it to other shapes in Microsoft Visio diagrams using Aspose.Diagram for Java. It is also possible to find connectors that are glued to this shape.

Getting Glued Shapes

The GluedShapes method exposed by the Shape class can be used to get a list of the IDs of all the connectors glued to a shape, or, if the shape in question is a connector, the IDs of the shapes it’s connected to.The GetShape method, exposed by the ShapeCollection class, can then be used to find a shape by its ID.

The code below shows how to:

  1. Load a sample file.
  2. Access a particular shape.
  3. Get a list of IDs of all the connectors glued to this shape.

Get Connectors Glued Programming Sample

Use the following code in your Java application to find all the connectors glued to a shape using Aspose.Diagram for Java.

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetGluedConnectors.class);
// call a Diagram class constructor to load the VSD diagram
Diagram diagram = new Diagram(dataDir + "RetrieveShapeInfo.vsd");
// get shape by an ID
Shape shape = diagram.getPages().get(0).getShapes().getShape(90);
// get all glued 1D shapes
long[] gluedShapeIds = shape.gluedShapes(GluedShapesFlags.GLUED_SHAPES_ALL_1_D, null, null);
// display shape ID and name
for (long id : gluedShapeIds)
{
shape = diagram.getPages().get(0).getShapes().getShape(id);
System.out.println("ID: " + shape.getID() + "\t\t Name: " + shape.getName());
}

Glue Visio Shapes Together with Connection Point

Aspose.Diagram for Java allows developers glue shapes together through the connection points.

Glue Shapes

The GlueShapes method exposed by the Page class can be used.

Input diagram

todo:image_alt_text

The diagram after gluing the shapes

todo:image_alt_text

The code below shows how to:
  1. Load a sample file.
  2. Glue shapes.
  3. Save diagram.

Glue Visio Shapes Programming Sample

Use the following code in your Java application to glue shapes through the connection points:

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GlueVisioShapes.class);
// Load diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// Get a particular page
Page page = diagram.getPages().getPage("Page-1");
// set shape id
long shape1_ID = 7;
long shape2_ID = 494;
// Glue shapes
page.glueShapes(shape1_ID, ConnectionPointPlace.CENTER, shape2_ID);
// Save diagram
diagram.save(dataDir + "GlueVisioShapes_Out.vsdx", SaveFileFormat.VSDX);

Glue Shapes Inside the Container

Aspose.Diagram for Java enables developers to glue group shapes inside a container.

Glue Group Shape

The GlueShapesInContainer method exposed by the Page class can be used.

Input diagram

todo:image_alt_text

The diagram after gluing the group shapes

todo:image_alt_text

The code below shows how to:
  1. Load a sample file.
  2. Glue group shapes.
  3. Save diagram.

Glue Shapes Inside Programming Sample

Use the following code in your Java application to glue group shape inside a container:

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GlueContainerShape.class);
// Load diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// Get a particular page
Page page = diagram.getPages().getPage("Page-1");
// The ID of shape which is glue from Aspose.Diagram.Shape.
long shapeFromId = 779;
// The location on the first connection index where to glue
int shapeToBeginConnectionIndex = 72;
// The location on the end connection index where to glue
int shapeToEndConnectionIndex = 73;
// The ID of shape where to glue to Aspose.Diagram.Shape.
long shapeToId = 743;
// Glue shapes in container
page.glueShapesInContainer(shapeFromId, shapeToBeginConnectionIndex, shapeToEndConnectionIndex, shapeToId);
// Glue shapes in container using connection name
// page.GlueShapesInContainer(fasId, "U05L", "U05R", cabinetId1);
// Save diagram
diagram.save(dataDir + "GlueContainerShape_Out.vsdx", SaveFileFormat.VSDX);