public static void GradientTransparencies() { int num_cols = 1; int num_rows = 10; var color1 = new ColorRGB(0xff000); var color2 = new 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 VA.DOM.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 static void DrawGridOfMasters() { // http://blogs.msdn.com/saveenr/archive/2008/08/06/visioautoext-simplifying-dropmany-to-quickly-draw-a-grid.aspx var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Resize the page to a sqaure var page_size = new VA.Drawing.Size(4, 4); SampleEnvironment.SetPageSize(page, page_size); // Load the Stencil var application = page.Application; var documents = application.Documents; var stencil = documents.OpenStencil("basic_u.vss"); var stencil_masters = stencil.Masters; var master = stencil_masters["Rectangle"]; // Calculate where to drop the masters int num_cols = 10; int num_rows = 10; var centerpoints = new List <VA.Drawing.Point>(num_rows * num_cols); foreach (var row in Enumerable.Range(0, num_rows)) { foreach (var col in Enumerable.Range(0, num_cols)) { var p = new VA.Drawing.Point(row * 1.0, col * 1.0); centerpoints.Add(p); } } var masters = new[] { master }; // Draw the masters var shapeids = page.DropManyU(masters, centerpoints); var bordersize = new VA.Drawing.Size(1, 1); page.ResizeToFitContents(bordersize); }
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 static void ColorGrid() { // Draws a grid rectangles and then formats the shapes // with different colors // Demonstrates: // How use the GridLayout object to quickly drop a grid // How to use ShapeFormatCells to apply formatting to shapes // How UpdateBase can be used to modfiy multiple shapes at once int[] colors = { 0x0A3B76, 0x4395D1, 0x99D9EA, 0x0D686B, 0x00A99D, 0x7ACCC8, 0x82CA9C, 0x74A402, 0xC4DF9B, 0xD9D56F, 0xFFF468, 0xFFF799, 0xFFC20E, 0xEB6119, 0xFBAF5D, 0xE57300, 0xC14000, 0xB82832, 0xD85171, 0xFEDFEC, 0x563F7F, 0xA186BE, 0xD9CFE5 }; const int num_cols = 5; const int num_rows = 5; var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var page_size = new VA.Geometry.Size(10, 10); SampleEnvironment.SetPageSize(page, page_size); var stencil = SampleEnvironment.Application.Documents.OpenStencil("basic_u.vss"); var master = stencil.Masters["Rectangle"]; var layout = new GridLayout(num_cols, num_rows, new VA.Geometry.Size(1, 1), master); layout.Origin = new VA.Geometry.Point(0, 0); layout.CellSpacing = new VA.Geometry.Size(0, 0); layout.RowDirection = RowDirection.BottomToTop; layout.PerformLayout(); layout.Render(page); var fmtcells = new VA.Shapes.ShapeFormatCells(); int i = 0; var writer = new SidSrcWriter(); foreach (var node in layout.Nodes) { var shapeid = node.ShapeID; int color_index = i % colors.Length; var color = colors[color_index]; fmtcells.FillForeground = new VisioAutomation.Models.Color.ColorRgb(color).ToFormula(); fmtcells.LinePattern = 0; fmtcells.LineWeight = 0; writer.SetValues(shapeid, fmtcells); i++; } writer.CommitFormulas(page); var bordersize = new VA.Geometry.Size(1, 1); page.ResizeToFitContents(bordersize); }