public void VDX_CustomTemplate() { string input_filename = this.GetTestResultsOutPath(@"datafiles\template_router.vdx"); string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx"); // Load the template string template_xml = File.ReadAllText(input_filename); var template = new VisioAutomation.VDX.Template(template_xml); var doc = new VisioAutomation.VDX.Elements.Drawing(template); var page = new VisioAutomation.VDX.Elements.Page(8, 4); doc.Pages.Add(page); // add layers var layer0 = page.AddLayer("Layer0", 0); var layer1 = page.AddLayer("Layer1", 1); var layer2 = page.AddLayer("Layer2", 2); // create layout var layout = new VisioAutomation.VDX.Sections.Layout(); layout.ShapeRouteStyle.Result = VisioAutomation.VDX.Enums.RouteStyle.TreeEW; // find the id of the master for rounded rectangles int shapeMasterNameId = doc.GetMasterMetaData("Router").ID; bool shapeMasterNameGroup = doc.GetMasterMetaData("Router").IsGroup; // add shape1 var shape1 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 1, 3); page.Shapes.Add(shape1); shape1.Text.Add("Router1"); shape1.Layout = layout; // add shape2 var shape2 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 5, 3); page.Shapes.Add(shape2); shape2.Text.Add("Router2"); shape2.Layout = shape1.Layout; // add shape3 - this is the dynamic connector var shape3 = VisioAutomation.VDX.Elements.Shape.CreateDynamicConnector(doc); shape3.XForm1D.BeginX.Result = 1; shape3.XForm1D.EndX.Result = 5; shape3.XForm1D.BeginY.Result = 3; shape3.XForm1D.EndY.Result = 3; page.Shapes.Add(shape3); shape3.Geom = new VisioAutomation.VDX.Sections.Geom(); shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.MoveTo(1, 3)); shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.LineTo(5, 3)); shape3.Layout = shape1.Layout; page.ConnectShapesViaConnector(shape3, shape1, shape2); // handle layers shape3.LayerMembership = new List<int> {layer0.Index, layer2.Index}; shape1.LayerMembership = new List<int> {layer1.Index}; shape2.LayerMembership = new List<int> {layer2.Index}; // write document to disk as .vdx file doc.Save(output_filename); this.VerifyDocCanBeLoaded(output_filename); }
public void VDX_CustomTemplate() { string input_filename = this.GetTestResultsOutPath(@"datafiles\template_router.vdx"); string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx"); // Load the template string template_xml = File.ReadAllText(input_filename); var template = new VisioAutomation.VDX.Template(template_xml); var doc = new VisioAutomation.VDX.Elements.Drawing(template); var page = new VisioAutomation.VDX.Elements.Page(8, 4); doc.Pages.Add(page); // add layers var layer0 = page.AddLayer("Layer0", 0); var layer1 = page.AddLayer("Layer1", 1); var layer2 = page.AddLayer("Layer2", 2); // create layout var layout = new VisioAutomation.VDX.Sections.Layout(); layout.ShapeRouteStyle.Result = VisioAutomation.VDX.Enums.RouteStyle.TreeEW; // find the id of the master for rounded rectangles int shapeMasterNameId = doc.GetMasterMetaData("Router").ID; bool shapeMasterNameGroup = doc.GetMasterMetaData("Router").IsGroup; // add shape1 var shape1 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 1, 3); page.Shapes.Add(shape1); shape1.Text.Add("Router1"); shape1.Layout = layout; // add shape2 var shape2 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 5, 3); page.Shapes.Add(shape2); shape2.Text.Add("Router2"); shape2.Layout = shape1.Layout; // add shape3 - this is the dynamic connector var shape3 = VisioAutomation.VDX.Elements.Shape.CreateDynamicConnector(doc); shape3.XForm1D.BeginX.Result = 1; shape3.XForm1D.EndX.Result = 5; shape3.XForm1D.BeginY.Result = 3; shape3.XForm1D.EndY.Result = 3; page.Shapes.Add(shape3); shape3.Geom = new VisioAutomation.VDX.Sections.Geom(); shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.MoveTo(1, 3)); shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.LineTo(5, 3)); shape3.Layout = shape1.Layout; page.ConnectShapesViaConnector(shape3, shape1, shape2); // handle layers shape3.LayerMembership = new List <int> { layer0.Index, layer2.Index }; shape1.LayerMembership = new List <int> { layer1.Index }; shape2.LayerMembership = new List <int> { layer2.Index }; // write document to disk as .vdx file doc.Save(output_filename); this.VerifyDocCanBeLoaded(output_filename); }