コード例 #1
0
        public void Scripting_Draw_Grid()
        {
            var origin   = new VisioAutomation.Drawing.Point(0, 4);
            var pagesize = new VisioAutomation.Drawing.Size(4, 4);
            var cellsize = new VisioAutomation.Drawing.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 VisioAutomation.Models.Layouts.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);
        }
コード例 #2
0
        public static void GradientTransparencies()
        {
            int num_cols = 1;
            int num_rows = 10;
            var color1   = new VAM.Color.ColorRgb(0xff000);
            var color2   = new VAM.Color.ColorRgb(0x000ff);

            var page_size = new VA.Geometry.Size(num_rows / 2.0, num_rows);
            var upperleft = new VA.Geometry.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 VAM.Layouts.Grid.GridLayout(num_cols, num_rows, new VA.Geometry.Size(6.0, 1.0), master);

            layout.RowDirection = VAM.Layouts.Grid.RowDirection.TopToBottom;
            layout.Origin       = upperleft;
            layout.CellSpacing  = new VA.Geometry.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 VAM.Dom.ShapeCells();
                node.Cells = fmt;

                fmt.FillPattern                = 25; // Linear pattern left to right
                fmt.FillForeground             = color1.ToFormula();
                fmt.FillBackground             = color2.ToFormula();
                fmt.FillForegroundTransparency = 0;
                fmt.FillBackgroundTransparency = transparency;
                fmt.LinePattern                = 0;

                node.Text = string.Format("bg trans = {0}%", transparency);
                i++;
            }

            layout.Render(page);

            page.ResizeToFitContents();
        }
コード例 #3
0
        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.Drawing.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 VA.Models.Layouts.Grid.GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master);

            layout.Origin       = new VA.Drawing.Point(0, 0);
            layout.CellSpacing  = new VA.Drawing.Size(0, 0);
            layout.RowDirection = VA.Models.Layouts.Grid.RowDirection.BottomToTop;

            layout.PerformLayout();
            layout.Render(page);

            var fmtcells = new VA.Shapes.ShapeFormatCells();
            int i        = 0;
            var writer   = new FormulaWriterSIDSRC();

            foreach (var node in layout.Nodes)
            {
                var shapeid     = node.ShapeID;
                int color_index = i % colors.Length;
                var color       = colors[color_index];
                fmtcells.FillForegnd = new ColorRGB(color).ToFormula();
                fmtcells.LinePattern = 0;
                fmtcells.LineWeight  = 0;
                fmtcells.SetFormulas(shapeid, writer);
                i++;
            }

            writer.Commit(page);

            var bordersize = new VA.Drawing.Size(1, 1);

            page.ResizeToFitContents(bordersize);
        }