Ejemplo n.º 1
0
        public static void Spirograph()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            page.Name = "Spirograph";

            var colors = new[]
            {
                0xf26420, 0xf7931c, 0xfec20d, 0xfff200,
                0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39,
                0x006f3a, 0x006f71, 0x008eb0, 0x00adee,
                0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091,
                0x5b57a6, 0x652d91, 0x92278e, 0xbd198c,
                0xec008b, 0xec1c23, 0xc1272c, 0x981a1e
            };

            var    origin             = new VA.Geometry.Point(4, 4);
            double radius             = 3.0;
            int    numpoints          = colors.Length;
            double angle_step         = (System.Math.PI * 2 / numpoints);
            var    angles             = Enumerable.Range(0, numpoints).Select(i => i * angle_step).ToList();
            var    centers            = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList();
            var    shapes             = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList();
            var    culture            = CultureInfo.InvariantCulture;
            var    angles_as_formulas = angles.Select(a => a.ToString(culture)).ToList();

            var color_formulas = colors.Select(x => new VA.Models.Color.ColorRgb(x).ToFormula()).ToList();

            var shapeids = shapes.Select(s => s.ID16).ToList();

            var writer = new SidSrcWriter();
            var format = new VA.Shapes.ShapeFormatCells();
            var xfrm   = new VA.Shapes.ShapeXFormCells();

            foreach (int i in Enumerable.Range(0, shapeids.Count))
            {
                short shapeid = shapeids[i];

                xfrm.Angle                        = angles_as_formulas[i];
                format.FillForeground             = color_formulas[i];
                format.LineWeight                 = 0;
                format.LinePattern                = 0;
                format.FillForegroundTransparency = 0.5;

                writer.SetValues(shapeid, xfrm);
                writer.SetValues(shapeid, format);
            }

            writer.Commit(page, VA.ShapeSheet.CellValueType.Formula);

            page.ResizeToFitContents(new VA.Geometry.Size(1.0, 1.0));
        }
Ejemplo n.º 2
0
        public static void ProgressBar()
        {
            var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add();


            // Draw some shapes
            var background = page_a.DrawRectangle(0, 0, 5, 1);
            var progress   = page_a.DrawRectangle(0, 0, 1, 1);

            var background_fmt = new VA.Shapes.ShapeFormatCells();

            background_fmt.FillForeground = "rgb(240,240,240)";
            background_fmt.LineColor      = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.ShapeFormatCells();

            progress_fmt.FillForeground = "rgb(100,150,240)";
            progress_fmt.LineColor      = "rgb(100,100,100)";

            // group the two shapes together
            page_a.Application.ActiveWindow.SelectAll();
            var group = page_a.Application.ActiveWindow.Selection.Group();

            // Set the progress shape update itself based on its position
            string bkname = background.NameID;
            var    xfrm   = new VA.Shapes.ShapeXFormCells();

            xfrm.PinX   = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xfrm.PinY   = string.Format("GUARD({0}!PinY)", bkname);
            xfrm.Width  = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xfrm.Height = string.Format("GUARD({0}!Height)", bkname);

            var writer = new SidSrcWriter();

            xfrm.SetFormulas(writer, progress.ID16);
            background_fmt.SetFormulas(writer, progress.ID16);
            progress_fmt.SetFormulas(writer, progress.ID16);

            writer.Commit(page_a);

            var markup1 = new VisioAutomation.Models.Text.Element();

            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VisioAutomation.Models.Text.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
Ejemplo n.º 3
0
        public void Set(VisioScripting.Models.TargetShapes targets, VisioAutomation.Shapes.ShapeFormatCells format)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            var writer   = new SidSrcWriter();
            var shapeids = targets.Shapes.Select(s => s.ID).ToList();

            foreach (int shapeid in shapeids)
            {
                format.SetFormulas((short)shapeid, writer);
            }

            var application = this._client.Application.Get();

            writer.Commit(application.ActivePage);
        }
Ejemplo n.º 4
0
        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);
        }