public void Scripting_Draw_Grid() { var origin = new VisioAutomation.Geometry.Point(0, 4); var pagesize = new VisioAutomation.Geometry.Size(4, 4); var cellsize = new VisioAutomation.Geometry.Size(0.5, 0.25); int cols = 3; int rows = 6; // Create the Page var client = this.GetScriptingClient(); client.Document.New(); client.Page.New(pagesize, false); // Find the stencil and master var stencildoc = client.Document.OpenStencil("basic_u.vss"); var master = client.Master.Get("Rectangle", stencildoc); // Draw the grid var page = client.Page.Get(); var grid = new GRID.GridLayout(cols, rows, cellsize, master); grid.Origin = origin; grid.Render(page); // Verify int total_shapes_expected = cols * rows; var shapes = page.Shapes.ToEnumerable().ToList(); int total_shapes_actual = shapes.Count; Assert.AreEqual(total_shapes_expected, total_shapes_actual); // Cleanup client.Document.Close(true); }
public void DrawGrid(VisioScripting.TargetPage targetpage, GRID.GridLayout layout) { targetpage = targetpage.ResolveToPage(this._client); layout.PerformLayout(); using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawGrid))) { layout.Render(targetpage.Page); } }
protected override void ProcessRecord() { var cellsize = new VA.Drawing.Size(this.CellWidth, this.CellHeight); var layout = new GRID.GridLayout(this.Columns, this.Rows, cellsize, this.Master); layout.CellSpacing = new VA.Drawing.Size(this.CellHorizontalSpacing, this.CellVerticalSpacing); layout.RowDirection = this.RowDirection; layout.ColumnDirection = this.ColumnDirection; this.WriteObject(layout); }
public void DrawGridOnActivePage(GRID.GridLayout layout) { var cmdtarget = this._client.GetCommandTargetPage(); var page = cmdtarget.ActivePage; layout.PerformLayout(); using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawGridOnActivePage))) { layout.Render(page); } }
public static void GradientTransparencies() { int num_cols = 1; int num_rows = 10; var color1 = new VisioAutomation.Colors.ColorRGB(0xff000); var color2 = new VisioAutomation.Colors.ColorRGB(0x000ff); var page_size = new VA.Drawing.Size(num_rows / 2.0, num_rows); var upperleft = new VA.Drawing.Point(0, page_size.Height); var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var app = page.Application; var docs = app.Documents; var stencil = docs.OpenStencil("basic_U.vss"); var master = stencil.Masters["Rectangle"]; SampleEnvironment.SetPageSize(page, page_size); var layout = new GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(6.0, 1.0), master); layout.RowDirection = GRIDMODEL.RowDirection.TopToBottom; layout.Origin = upperleft; layout.CellSpacing = new VA.Drawing.Size(0.1, 0.1); layout.PerformLayout(); double[] trans = EffectsSamples.RangeSteps(0.0, 1.0, num_rows).ToArray(); int i = 0; foreach (var node in layout.Nodes) { double transparency = trans[i]; var fmt = new ShapeCells(); node.Cells = fmt; fmt.FillPattern = 25; // Linear pattern left to right fmt.FillForegnd = color1.ToFormula(); fmt.FillBkgnd = color2.ToFormula(); fmt.FillForegndTrans = 0; fmt.FillBkgndTrans = transparency; fmt.LinePattern = 0; node.Text = string.Format("bg trans = {0}%", transparency); i++; } layout.Render(page); page.ResizeToFitContents(); }
public void Grid(GRID.GridLayout layout) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); //Create a new page to hold the grid var application = this._client.Application.Get(); var page = application.ActivePage; layout.PerformLayout(); using (var undoscope = this._client.Application.NewUndoScope("Draw Grid")) { layout.Render(page); } }
public List <IVisio.Shape> DrawDataTable(VisioScripting.TargetPage targetpage, System.Data.DataTable datatable, IList <double> widths, IList <double> heights, VisioAutomation.Geometry.Size cellspacing) { if (datatable == null) { throw new System.ArgumentNullException(nameof(datatable)); } if (widths == null) { throw new System.ArgumentNullException(nameof(widths)); } if (heights == null) { throw new System.ArgumentNullException(nameof(heights)); } if (datatable.Rows.Count < 1) { throw new System.ArgumentOutOfRangeException(nameof(datatable), "DataTable must have at least one row"); } targetpage = targetpage.ResolveToPage(this._client); string master = "Rectangle"; string stencil = "basic_u.vss"; var stencildoc = this._client.Document.OpenStencilDocument(stencil); var stencildoc_masters = stencildoc.Masters; var masterobj = stencildoc_masters.ItemU[master]; targetpage.Page.Background = 0; // ensure this is a foreground page var pagesize = VisioAutomation.Pages.PageHelper.GetSize(targetpage.Page); var layout = new GRID.GridLayout(datatable.Columns.Count, datatable.Rows.Count, new VisioAutomation.Geometry.Size(1, 1), masterobj); layout.Origin = new VisioAutomation.Geometry.Point(0, pagesize.Height); layout.CellSpacing = cellspacing; layout.RowDirection = GRID.RowDirection.TopToBottom; layout.PerformLayout(); foreach (var i in Enumerable.Range(0, datatable.Rows.Count)) { var row = datatable.Rows[i]; for (int col_index = 0; col_index < row.ItemArray.Length; col_index++) { var col = row.ItemArray[col_index]; var cur_label = (col != null) ? col.ToString() : string.Empty; var node = layout.GetNode(col_index, i); node.Text = cur_label; } } using (var undoscope = this._client.Undo.NewUndoScope(nameof(DrawDataTable))) { layout.Render(targetpage.Page); targetpage.Page.ResizeToFitContents(); } var shapes = layout.Nodes.Select(n => n.Shape).ToList(); return(shapes); }
public static void DrawAllGradients() { var app = SampleEnvironment.Application; var docs = app.Documents; var stencil = docs.OpenStencil("basic_u.vss"); var master = stencil.Masters["Rectangle"]; var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); int num_cols = 7; int num_rows = 7; var page_size = new VA.Drawing.Size(5, 5); SampleEnvironment.SetPageSize(page, page_size); var lowerleft = new VA.Drawing.Point(0, 0); var actual_page_size = SampleEnvironment.GetPageSize(page); var page_rect = new VA.Drawing.Rectangle(lowerleft, actual_page_size); var layout = new GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master); layout.RowDirection = GRIDMODEL.RowDirection.TopToBottom; layout.Origin = page_rect.UpperLeft; layout.CellSpacing = new VA.Drawing.Size(0, 0); layout.PerformLayout(); int max_grad_id = 40; int n = 0; foreach (var node in layout.Nodes) { int grad_id = n % max_grad_id; node.Text = grad_id.ToString(); n++; } layout.Render(page); var color1 = new VA.Colors.ColorRGB(0xffdddd); var color2 = new VA.Colors.ColorRGB(0x00ffff); var format = new VA.Shapes.ShapeFormatCells(); var writer = new FormulaWriterSIDSRC(); string color1_formula = color1.ToFormula(); string color2_formula = color2.ToFormula(); n = 0; foreach (var node in layout.Nodes) { short shapeid = node.ShapeID; int grad_id = n % max_grad_id; format.FillPattern = grad_id; format.FillForegnd = color1_formula; format.FillBkgnd = color2_formula; format.LinePattern = 0; format.LineWeight = 0; format.SetFormulas(shapeid, writer); n++; } writer.Commit(page); var bordersize = new VA.Drawing.Size(1, 1); page.ResizeToFitContents(bordersize); }
public List <IVisio.Shape> Table(System.Data.DataTable datatable, IList <double> widths, IList <double> heights, VisioAutomation.Geometry.Size cellspacing) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); if (datatable == null) { throw new System.ArgumentNullException(nameof(datatable)); } if (widths == null) { throw new System.ArgumentNullException(nameof(widths)); } if (heights == null) { throw new System.ArgumentNullException(nameof(heights)); } if (datatable.Rows.Count < 1) { return(new List <IVisio.Shape>(0)); } string master = "Rectangle"; string stencil = "basic_u.vss"; var stencildoc = this._client.Document.OpenStencil(stencil); var stencildoc_masters = stencildoc.Masters; var masterobj = stencildoc_masters.ItemU[master]; var app = this._client.Application.Get(); var application = app; var active_document = application.ActiveDocument; var pages = active_document.Pages; var page = pages.Add(); page.Background = 0; // ensure this is a foreground page var pagesize = this._client.Page.GetSize(); var layout = new GRID.GridLayout(datatable.Columns.Count, datatable.Rows.Count, new VisioAutomation.Geometry.Size(1, 1), masterobj); layout.Origin = new VisioAutomation.Geometry.Point(0, pagesize.Height); layout.CellSpacing = cellspacing; layout.RowDirection = GRID.RowDirection.TopToBottom; layout.PerformLayout(); foreach (var i in Enumerable.Range(0, datatable.Rows.Count)) { var row = datatable.Rows[i]; for (int col_index = 0; col_index < row.ItemArray.Length; col_index++) { var col = row.ItemArray[col_index]; var cur_label = (col != null) ? col.ToString() : string.Empty; var node = layout.GetNode(col_index, i); node.Text = cur_label; } } using (var undoscope = this._client.Application.NewUndoScope("Draw Table")) { layout.Render(page); page.ResizeToFitContents(); } var page_shapes = page.Shapes; var shapes = layout.Nodes.Select(n => n.Shape).ToList(); return(shapes); }