Create, Layout and Auto-Fit Shapes
Creating a Diagram
Aspose.Diagram for Java lets you read and create Microsoft Visio diagrams from within your own applications, without Microsoft Office Automation. The first step when creating new documents, is to create a diagram. Then add shapes and connectors to build up the diagram. Use the default constructor of Diagram class to create a new diagram.
Programming Sample
Layout Shapes in Flowchart Style
With certain types of connected drawings, such as flowcharts and network diagrams, you can use the Layout Shapes feature to automatically position shapes. Automatically positioning is faster than manually dragging each shape to a new location.
For example, if you’re updating a large flowchart to include a new process, you can add and connect the shapes that make up the process, and then use the layout feature to automatically layout the updated drawing.
The Layout method, exposed by the Diagram class layouts the shapes and/or reroutes the connectors on all the diagram’s pages. This method accepts an LayoutOptions object as an argument. Use the different properties exposed by the LayoutOptions class to automatically layout shapes.
The image below shows the diagram loaded by the code snippets in this article, before auto layout is applied. The code snippets show how to apply flowchart layouts and compact tree layouts.
The source diagram.
The code snippets in this article takes the source diagram and applies several types of auto layout to it, saving each in a separate file.
Layout shapes bottom to top |
Layout shapes top to bottom |
---|---|
Layout shapes left to right |
Layout shapes right to left |
To layout shapes in flowchart style: |
- Create an instance of the Diagram class.
- Create an instance of LayoutOptions class and set Flowchart style related properties.
- Call the Diagram class' Layout method by passing LayoutOptions.
- Call the Diagram class' Save method to write the Visio drawing.
Flowchart Style Programming Sample
Laying Out Shapes in the Compact Tree Style
The compact tree layout style tries to built a tree structure. It uses the same input file as the example above and saves out to several different compact tree styles.
Compact tree layout - down and right |
---|
Compact tree layout - down and left |
Compact tree layout - right and down |
Compact tree layout - left and down |
---|---|
To layout shapes in the compact tree style: |
- Create an instance of the Diagram class.
- Create an instance of the LayoutOptions class and set compact tree style properties.
- Call the Diagram class' Layout method by passing LayoutOptions.
- Call the the Diagram class' Save method to write the Visio file.
Compact Tree Style Programming Sample
Auto-fit the Visio Diagram
Aspose.Diagram API supports auto-fitting of the Visio drawing. This feature operation helps to bring outside shapes inside the Visio page boundary.
Aspose.Diagram for Java API has the Diagram class that represents a Visio drawing. The DiagramSaveOptions class exposes AutoFitPageToDrawingContent property to auto fit the Visio drawing.
This example work as follows:
- Create an object of the Diagram class.
- Create an object of the DiagramSaveOptions class and pass the resultant file format.
- Set AutoFitPageToDrawingContent property of the DiagramSaveOptions object.
- Call Save method of the Diagram class object and also pass complete file path and the DiagramSaveOptions object.
Auto-fit Programming Sample
The following example code shows how to auto-fit shapes in the Visio diagram.
Working with VBA Project
Modify VBA Module Code in Visio Diagram
This article demonstrates how to modify a VBA module code automatically using Aspose.Diagram for Java.
We have added VbaModule, VbaModuleCollection, VbaProject, VbaProjectReference and VbaProjectReferenceCollection classes. These classes help to get control over VBA project. Developers can extract and modify VBA module code.
Modify VBA Module Code Programming Sample
Please check this code example:
Remove All Macros from the Visio Diagram
Aspose.Diagram for Java allows developers to remove all macros from the Visio diagram.
The JavaProjectData property, exposed by the Diagram class, allows you to remove all macros from the Visio drawing.