We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating new Shape Order of Operations

In the examples, a new shape is added to a diagram using the following code:


long shapeId = page.addShape(x, y, width, height, masterName);
Shape shape = page.getShapes().getShape(shapeId);
// Set the new shape’s properties

Due to the organization of my code, I need to create a new shape object first then add it to the diagram second. For example:

Shape shape = new Shape();
// Set the new shape’s properties
page.addShape(shape);


Is is possible to do it this way? If so, can you provide an example?

Hi Chris,


Thank you for contacting support. Yes, you can add a new shape by initializing an object of Shape class, but you also need to pass master name. Please have a look on this sample code:

[Java]

// load visio stencil<o:p></o:p>

Diagram diagram = new Diagram("C:\\Basic Shapes.vss");

String masterName = "Circle";

// get page object

Page page = diagram.getPages().getPage(0);

// initialilze shape object

Shape shape = new Shape();

// set shape name

shape.setName("ShapeName");

// add shape

page.addShape(shape, masterName);

// save diagram

diagram.save(“C:\Output.vdx”, SaveFileFormat.VDX);


Please feel free to reply us in case of any confusion or questions.