Group, Convert and Verify Shapes

Group Multiple Shapes Together in the Visio Drawing

Aspose.Diagram API allows developers in grouping shapes together to move them all at once. Each shape in a group maintains a unique identity and has its own set of properties. When we change the formatting of a group of shapes, it assigns the new property to each shape.

How to Group Shapes

The Group method exposed by the ShapeCollection class can be used to group shapes together.

The code below shows how to:

  1. Load a sample diagram.
  2. initialized an array of the shapes
  3. get a particular shape by id.
  4. get another particular particular shape by id.
  5. assign shapes to the array.
  6. group shapes by calling the Group method.
  7. save diagram

Group Shapes Programming Sample

Use the following code in your Java application to group shapes together using Aspose.Diagram for Java API.

Convert a Visio Shape to Other File Formats

Aspose.Diagram for Java API allows developers to convert a single Visio shape to any other supported file format. In this article, we remove all other Visio shapes from the page and customize page setting according to the source Shape size. 

Converting a Particular Visio Shape

Developers can convert a Visio shape to PDF, HTML, Image, SVG, and SWF by specifying the Visio save options. This example code work as follows:

  1. Load a source Visio.
  2. Get a particular page.
  3. Remove the background page.
  4. Build a hash table of all shapes holding the ids and names.
  5. Iterate through the hash table
  6. Remove all shapes from the Visio page, except the particular one.
  7. Set the page size.
  8. Save the Visio page in any supported file format.

Convert Shape Programming Sample

Convert Visio Shape to PDF

The ToPdf method of the Shape class allows to convert a shape into the PDF format.

 // import diagram

Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

// save a shape in the PDF format

diagram.getPages().get(0).getShapes().getShape(59).toPdf(dataDir + "out.pdf");

Convert Visio Shape to HTML

The ToHTML method of the Shape class allows to convert a shape into the HTML format.

 // import diagram

Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

HTMLSaveOptions hs = new HTMLSaveOptions();

// save a shape in the PDF format

diagram.getPages().get(0).getShapes().getShape(59).toHTML(dataDir + "out.pdf", hs);

Verify Whether Two Visio Shapes are Connected or Glued

Aspose.Diagram for Java API allows developers to verify that the two Visio shapes are glued or connected. Previously, we have seen that how we can connect or glue two shapes in these help topics: Add and Connect Visio Shapes and Glue Shapes Inside the Container.

Verification of the Connected or Glued Shapes

The Shape class offers IsGlued and IsConnected properties to determine whether two shapes are glued or connected.

Verification of Connected or Glued Shapes Programming Sample

The following piece of code verifies whether two shapes are connected or glued.

Verify Whether the Visio Shape is in a Group of Shapes

Aspose.Diagram for Java API allows developers to verify that the Visio shape is in a group of shapes or not.

Verification of Shape in the Group of Shapes

The Shape class offers IsInGroup properties to determine whether the Visio shape is in a group shape.

Verification of Shape in the Group of Shapes Programming Sample

The following piece of code verifies whether the shape is in a group shape.