public IVisio.Page Render(IVisio.Document doc) { if (!this.IsLayedOut) { string msg = string.Format("{0} usage error. {1}() before calling {2}().", nameof(ContainerLayout), nameof(PerformLayout), nameof(Render)); throw new System.ArgumentException(msg); } // create a new drawing var app = doc.Application; var docs = app.Documents; var pages = doc.Pages; var page = pages.Add(); // load the stencil used to draw the items var item_stencil = docs.OpenStencil(this.LayoutOptions.ManualItemStencil); var item_stencil_masters = item_stencil.Masters; var item_master = item_stencil_masters[this.LayoutOptions.ManualItemMaster]; var plain_container_master = item_stencil_masters[this.LayoutOptions.ManualContainerMaster]; var page_shapes = page.Shapes; // Drop the container shapes var ct_items = this.Containers.ToList(); var ct_rects = ct_items.Select(item => item.Rectangle).ToList(); var masters = ct_items.Select(i => plain_container_master).ToList(); short[] ct_shapeids = ContainerLayout._drop_many_u(page, masters, ct_rects); // associate each container with the corresponding shape oject and shape id for (int i = 0; i < ct_items.Count; i++) { var ct_item = ct_items[i]; var ct_shapeid = ct_shapeids[i]; var shape = page_shapes[ct_shapeid]; ct_item.VisioShape = shape; ct_item.ShapeID = ct_shapeid; } // Render the items var items = this.ContainerItems.ToList(); var item_rects = items.Select(item => item.Rectangle).ToList(); var item_masters = items.Select(i => item_master).ToList(); short[] shapeids = ContainerLayout._drop_many_u(page, item_masters, item_rects); // Associate each item with the corresponding shape object and shape id for (int i = 0; i < items.Count; i++) { var item = items[i]; var shapeid = shapeids[i]; var shape = page_shapes[shapeid]; item.VisioShape = shape; item.ShapeID = shapeid; } // Often useful to show everthing because these diagrams can get large app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; // Set the items foreach (var item in items.Where(i => i.Text != null)) { item.VisioShape.Text = item.Text; } var writer = new SidSrcWriter(); // Format the containers and shapes foreach (var item in this.Containers) { this.LayoutOptions.ContainerFormatting.Apply(writer, item.ShapeID, item.ShapeID); } foreach (var item in this.ContainerItems) { this.LayoutOptions.ContainerItemFormatting.Apply(writer, item.ShapeID, item.ShapeID); } writer.BlastGuards = true; writer.Commit(page, ShapeSheet.CellValueType.Formula); // Set the Container Text foreach (var ct in this.Containers) { if (ct.Text != null) { ct.Text.SetText(ct.VisioShape); } } page.ResizeToFitContents(); app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; return(page); }