Hi,
I’m working on an urgent project which involves taking hierarchical data and turning it into a Visio org chart.
I know that Aspose Diagram does not support this directly so I have written my own code to get this.
The portion of this which appears to be broken is the ability to re-layout the code. Although I call this code it doesn’t seem to apply the re-layout. So here is the code so you can test directly.
protected void Button1_Click(object sender, EventArgs e)
{
License diagramLicense = new License();
diagramLicense.SetLicense("Aspose.Total.lic");
// Load masters from any existing diagram, stencil or template
// And add in the new diagram
const string visioStencil = "D:\\Drawing1.vss";
const string rectangleMaster = @"Rectangle";
const string connectorMaster = "Dynamic connector";
const int pageNumber = 0;
const double width = 1;
const double height = 1;
double pinX = 4.25;
double pinY = 9.5;
// Define values to construct the hierarchy
List listPos = new List(new string[] { "0", "0:0", "0:1", "0:2", "0:3", "0:4", "0:5", "0:6", "0:0:0", "0:0:1", "0:3:0", "0:3:1", "0:3:2", "0:6:0", "0:6:1" });
// define a list to hold the split values
List list = new List();
// Create a new diagram
Diagram diagram = new Diagram(visioStencil);
foreach (string orgnode in listPos)
{
// Add a new rectangle shape
long rectangleId = diagram.AddShape(
pinX++, pinY++, width, height, rectangleMaster, pageNumber);
// Set the new shape's properties
Shape shape = diagram.Pages[pageNumber].Shapes.GetShape(rectangleId);
shape.Text.Value.Add(new Txt(orgnode));
shape.Name = orgnode;
list.Add(shape.Name.Split(':'));
}
// Create connections between nodes
int shapeId = 2;
foreach (string[] strArr in list)
{
// convert the string array into int array
int[] myInts = Array.ConvertAll(strArr, int.Parse);
if (myInts.Length > 1)
{
var parent = myInts[myInts.Length - 2];
parent = parent + myInts.Length - 1;
Shape connector1 = new Shape();
long connecter1Id = diagram.AddShape(connector1, connectorMaster, 0);
diagram.Pages[0].ConnectShapesViaConnector(parent, ConnectionPointPlace.Bottom,
shapeId, ConnectionPointPlace.Top, connecter1Id);
shapeId++;
}
}
LayoutOptions compactTreeOptions = new LayoutOptions
{
LayoutStyle = LayoutStyle.FlowChart,
Direction = LayoutDirection.TopToBottom
};
//compactTreeOptions.EnlargePage = true;
diagram.Layout(compactTreeOptions);
// Save the diagram
diagram.Save("D:\\OrgChart.vdx", SaveFileFormat.VDX);
}
I’ve attached the two images. The first show what I see in the Visio diagram. The second shows what needs to be clicked inside Visio in order to get the results I would expected.
I would appreciate a speedy resolution as this is on the critical path of a project I’m working on.
Thanks,
Andy.