public void Render(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } // First handle any page properties if (this.Name != null) { page.NameU = this.Name; } this.VisioPage = page; var page_sheet = page.PageSheet; var app = page.Application; using (var perfscope = new Application.PerfScope(app, this.PerfSettings)) { if (this.Size.HasValue) { this.PageCells.PageHeight = this.Size.Value.Height; this.PageCells.PageWidth = this.Size.Value.Width; } var update = new ShapeSheet.Update(); update.SetFormulas((short)page_sheet.ID, this.PageCells); update.Execute(page); // Then render the shapes this.Shapes.Render(page); // Perform any additional layout if (this.Layout != null) { this.Layout.Apply(page); } // Optionally, perform page resizing to fit contents if (this.ResizeToFit) { if (this.ResizeToFitMargin.HasValue) { page.ResizeToFitContents(this.ResizeToFitMargin.Value); } else { page.ResizeToFitContents(); } } } }
public void Render(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } // First handle any page properties if (this.Name != null) { page.NameU = this.Name; } this.VisioPage = page; var page_sheet = page.PageSheet; var app = page.Application; using (var perfscope = new RenderPerformanceScope(app, this.RenderPerforfmanceSettings)) { if (this.Size.HasValue) { this.PageFormatCells.Height = this.Size.Value.Height; this.PageFormatCells.Width = this.Size.Value.Width; } var writer = new SidSrcWriter(); writer.SetValues((short)page_sheet.ID, this.PageFormatCells); writer.SetValues((short)page_sheet.ID, this.PageLayoutCells); writer.Commit(page, ShapeSheet.CellValueType.Formula); // Then render the shapes this.Shapes.Render(page); // Perform any additional layout if (this.Layout != null) { this.Layout.Apply(page); } // Optionally, perform page resizing to fit contents if (this.ResizeToFit) { if (this.ResizeToFitMargin.HasValue) { page.ResizeToFitContents(this.ResizeToFitMargin.Value); } else { page.ResizeToFitContents(); } } } }
public void Render(IVisio.Page page, DirectedGraphLayout dglayout) { // Create A DOM and render it to the page var app = page.Application; var page_node = this.CreateDomPage(dglayout, app, this.Styling); page_node.Render(page); // Find all the shapes that were created in the DOM and put them in the layout structure foreach (var layout_shape in dglayout.Nodes) { var shape_node = layout_shape.DomNode; layout_shape.VisioShape = shape_node.VisioShape; } var layout_edges = dglayout.Edges; foreach (var layout_edge in layout_edges) { var vnode = layout_edge.DomNode; layout_edge.VisioShape = vnode.VisioShape; } page.ResizeToFitContents(LayoutOptions.PageBorderWidth); }
public static void Render(IVisio.Page page, VisioAutomation.Models.DirectedGraph.Drawing drawing, DGMODEL.MSAGLLayoutOptions options) { var renderer = new VA.Models.DirectedGraph.MSAGLRenderer(); renderer.LayoutOptions = options; renderer.Render(drawing, page); page.ResizeToFitContents(renderer.LayoutOptions.ResizeBorderWidth); }
/// <summary> /// Create a new page in a Visio file showing all the direct entity relationships participated in /// by the passed-in array of entities. /// </summary> /// <param name="entities">Core entities for the diagram</param> /// <param name="worker">The worker.</param> /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param> private void BuildDiagram(List <string> entities, BackgroundWorker worker, DoWorkEventArgs e) { // Get the default page of our new document VisioApi.Page page = _document.Pages[1]; page.Name = "MSCRMToolKit generated diagram"; int cptEntititesTreated = 0; // Get the metadata for each passed-in entity, draw it, and draw its relationships. foreach (string entityName in entities) { if (worker.CancellationPending) { e.Cancel = true; return; } cptEntititesTreated++; worker.ReportProgress(cptEntititesTreated); EntityMetadata entity = GetEntityMetadata(entityName); // Create a Visio rectangle shape. VisioApi.Shape rect; try { // There is no "Get Try", so we have to rely on an exception to tell us it does not exists // We have to skip some entities because they may have already been added by relationships of another entity rect = page.Shapes.get_ItemU(entity.LogicalName); } catch (System.Runtime.InteropServices.COMException) { rect = DrawEntityRectangle(page, entity); } // Draw all relationships TO this entity. DrawRelationships(entity, rect, entity.ManyToManyRelationships, false, worker, e); DrawRelationships(entity, rect, entity.ManyToOneRelationships, false, worker, e); // Draw all relationshipos FROM this entity DrawRelationships(entity, rect, entity.OneToManyRelationships, true, worker, e); } // Arrange the shapes to fit the page. page.Layout(); page.ResizeToFitContents(); }
/// <summary> /// Create a new page in a Visio file showing all the direct entity relationships participated in /// by the passed-in array of entities. /// </summary> /// <param name="entities">Core entities for the diagram</param> /// <param name="pageTitle">Page title</param> private void BuildDiagram(string[] entities, string pageTitle) { // Get the default page of our new document VisioApi.Page page = _document.Pages[1]; page.Name = pageTitle; int i = 1; // Get the metadata for each passed-in entity, draw it, and draw its relationships. foreach (string entityName in entities) { Console.Write("Processing entity {1}/{2} {3}: {0}", entityName, i, entities.Length, DateTime.Now.ToLongTimeString()); EntityMetadata entity = GetEntityMetadata(entityName); // Create a Visio rectangle shape. VisioApi.Shape rect; try { // There is no "Get Try", so we have to rely on an exception to tell us it does not exists // We have to skip some entities because they may have already been added by relationships of another entity rect = page.Shapes.get_ItemU(entity.LogicalName); } catch (System.Runtime.InteropServices.COMException) { rect = DrawEntityRectangle(page, entity.LogicalName, null == entity.DisplayName.UserLocalizedLabel ? "" : entity.DisplayName.UserLocalizedLabel.Label, entity.OwnershipType.Value); Console.Write('.'); // Show progress } // Draw all relationships TO this entity. DrawRelationships(entity, rect, entity.ManyToManyRelationships, false); Console.Write('.'); // Show progress DrawRelationships(entity, rect, entity.ManyToOneRelationships, false); // Draw all relationshipos FROM this entity DrawRelationships(entity, rect, entity.OneToManyRelationships, true); Console.WriteLine('.'); // Show progress i++; } // Arrange the shapes to fit the page. page.Layout(); page.ResizeToFitContents(); }
public static void Render(IVisio.Page page, DirectedGraphLayout directedGraphLayout, MsaglLayoutOptions options) { if (page == null) { throw new ArgumentNullException(nameof(page)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var renderer = new MsaglRenderer(); renderer.LayoutOptions = options; renderer.Render(directedGraphLayout, page); page.ResizeToFitContents(renderer.LayoutOptions.ResizeBorderWidth); }
public static void ResizeToFitContents(IVisio.Page page, Geometry.Size padding) { // first perform the native resizetofit page.ResizeToFitContents(); if ((padding.Width > 0.0) || (padding.Height > 0.0)) { // if there is any additional padding requested // we need to further handle the page // first determine the desired page size including the padding // and set the new size var old_size = VisioAutomation.Pages.PageHelper.GetSize(page); var new_size = old_size + padding.Multiply(2, 2); VisioAutomation.Pages.PageHelper.SetSize(page, new_size); // The page has the correct size, but // the contents will be offset from the correct location page.CenterDrawing(); } }
public void AddShapes() { Visio.Application visio = this.Application; Visio.Documents documents = this.Application.Documents; Visio.Page page = visio.ActivePage; Visio.Document document = visio.ActiveDocument; if (document == null) { document = visio.Documents.Add(""); } if (page == null) { page = document.Pages.Add(); } List <Service> services = null; try { ServicesApi api = new ServicesApi(); services = api.getServices(true, ""); } catch (ApiException e) { System.Windows.Forms.MessageBox.Show("Error calling the LeanIX API: " + e.Message); return; } catch (System.Net.WebException) { System.Windows.Forms.MessageBox.Show("Please check your internet connection"); return; } if (services == null || services.Count == 0) { System.Windows.Forms.MessageBox.Show("No data received from API"); return; } Dictionary <String, Visio.Shape> placedShapes = new Dictionary <String, Visio.Shape>(); //add shapes foreach (Service s in services) { if (s.serviceHasInterfaces == null || s.serviceHasInterfaces.Count == 0) { continue; } Visio.Document stencil = documents.OpenEx("Basic Shapes.vss", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked); Visio.Master visioRectMaster = stencil.Masters.get_ItemU(@"Rounded Rectangle"); Visio.Shape visioRectShape = page.Drop(visioRectMaster, 0, 0); visioRectShape.Text = s.name; placedShapes.Add(s.ID, visioRectShape); } //connect shapes foreach (Service s in services) { foreach (ServiceHasInterface si in s.serviceHasInterfaces) { Visio.Shape sourceShape = placedShapes[s.ID]; Visio.Shape targetShape = placedShapes[si.serviceRefID]; if (targetShape != null) { sourceShape.AutoConnect(targetShape, Visio.VisAutoConnectDir.visAutoConnectDirLeft); } } } //set the layout and resize the page page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOPlaceStyle).ResultIU = 6; page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLORouteStyle).ResultIU = 1; page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOSplit).ResultIU = 1; page.Layout(); page.ResizeToFitContents(); }