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

Free Support Forum - aspose.com

Creating diagram from Template not working right

Hello, I’m trying to create diagrams from a VSTX file, which has several Masters, some header and footer text, and a large page size.


When I use
var diagram(“MyTemplate.vstx”);
var shapeId1 = diagram.AddShape(1, 1, 1, 1, “Master1Name”, 0);
var shapeId2 = diagram.AddShape(2, 2, 2, 2, “Master2Name”, 0);
diagram.Save(“MyDiagram.vsdx”, SaveFileFormat.VSDX);

… it works for the first shape, but not for the second – unless I call AddShape twice for the second shape. (I’m guessing it has something to do with getting the Masters in place, which works differently between Template and Diagram file formats, perhaps.)

When I try instead to create from scratch per your example…

var template = new Diagram(“MyTemplate.vstx”);
var diagram = new Diagram();
foreach (Master master in template.Masters)
diagram.AddMaster(template, master.Name);
diagram.CopyTheme(template);
<span style=“font-family: “Courier New”;”>diagram.Save(“MyDiagram.vsdx”, SaveFileFormat.VSDX);

… adding Shapes works fine, but this logic doesn’t copy the page size/orientation or header/footer from the Template.

Can you point me to the simplest way to create diagrams from a template?
Thanks!

Hi,

It appears as a bug because it is not working for the second AddShape method call. Please provide us with your source template file and code. We shall investigate and reply to you appropriately. Your response is awaited.

Thank you for such a fast response. I would like to get you a condensed version of the template and code to repro the bug, if it is one, but that will take some effort. Meanwhile, is there a good example of code that creates shapes on a Diagram based on Masters in a Template? Or is there some other way that this goal can be accomplished?


Thanks.

Hi,


Thank you for the inquiry. Aspose.Diagram API adds shapes based on the Master because each shape is an extended form of a unique master. You can add master from other stencil files or Visio drawings. Aspose.Diagram API also allows to create a Master from scratch. Please refer to these help topics: Add a new Shape in Visio, Add and Connect Visio Shapes and Create a Master from Scratch

Hello,
I am attaching a zip with a Diagram (created from our user's Template file), which the Unit test below opens and add shapes to, using Master shapes.
There is no error, but the 2nd shape does not appear on the diagram.

[TestMethod]
public void Test_TemplateSavedAsDiagram7()
{
//Fails to show shape 2.
var diagram = new Diagram("Template7.vsdx");
var shapeId = diagram.AddShape(2, 12, 3, 2, "Organization", 0);
var shape = diagram.Pages[0].Shapes.GetShape(shapeId);
shape.Text.Value.Add(new Txt("Org 1"));

shapeId = diagram.AddShape(5, 12, 2, 1, "ANSP", 0);
shape = diagram.Pages[0].Shapes.GetShape(shapeId);
shape.Text.Value.Add(new Txt("ANSP 2"));

shapeId = diagram.AddShape(8, 12, 2, 1, "ANSP", 0);
shape = diagram.Pages[0].Shapes.GetShape(shapeId);
shape.Text.Value.Add(new Txt("ANSP 3"));

diagram.Save("Result7.vsdx", SaveFileFormat.VSDX);
}

If this is a bug, can you offer a work-around? Do you have examples of how to modify Template files to generate Diagrams?

Many thanks for your attention to this inquiry.

Hi,


Thank you for the details. We have tested your source Visio drawing against the latest version 17.3.1.0 of Aspose.Diagram for .NET API. When we opened the output VSDX in the Microsoft Visio viewer 2013, it shows three shapes. Please download and try the latest Hotfix version: Aspose.Diagram for .NET 17.3.1.0 and let us know how that goes on your side. We have attached the output VSDX drawing to this reply for your kind reference.

I was able to confirm that the latest version we have, 17.3.2.0, fixes this problem.

Thanks.