Beispiel #1
0
 public void Apply(VA.ShapeSheet.Update update, short shapeid_label, short shapeid_box)
 {
     update.SetFormulas(shapeid_label, this.CharacterCells, 0);
     update.SetFormulas(shapeid_label, this.ParagraphCells, 0);
     update.SetFormulas(shapeid_box, this.FormatCells);
     update.SetFormulas(shapeid_label, this.TextCells);
 }
Beispiel #2
0
        public void ApplyFormus(VA.ShapeSheet.Update update)
        {
            short titleshape_id = this.VisioShape.ID16;

            update.SetFormulas(titleshape_id, this.Textcells);
            update.SetFormulas(titleshape_id, this.ParagraphCells, 0);
            update.SetFormulas(titleshape_id, this.CharacterCells, 0);
            update.SetFormulas(titleshape_id, this.FormatCells);
        }
Beispiel #3
0
        public void ToogleCase(IList <IVisio.Shape> target_shapes)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Toggle Shape Text Case"))
            {
                var shapeids = shapes.Select(s => s.ID).ToList();

                var page = this.Client.VisioApplication.ActivePage;
                // Store all the formatting
                var formats = VA.Text.TextFormat.GetFormat(page, shapeids);

                // Change the text - this will wipe out all the character and paragraph formatting
                foreach (var shape in shapes)
                {
                    string t = shape.Text;
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    shape.Text = TextCommandsUtil.toggle_case(t);
                }

                // Now restore all the formatting - based on any initial formatting from the text

                var update = new VA.ShapeSheet.Update();
                for (int i = 0; i < shapes.Count; i++)
                {
                    var format = formats[i];

                    if (format.CharacterFormats.Count > 0)
                    {
                        var fmt = format.CharacterFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }

                    if (format.ParagraphFormats.Count > 0)
                    {
                        var fmt = format.ParagraphFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }
                }

                update.Execute(page);
            }
        }
Beispiel #4
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.FormatCells();

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


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

            progress_fmt.FillForegnd = "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    xform  = new VA.Shapes.XFormCells();

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

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(progress.ID16, xform);
            update.SetFormulas(progress.ID16, background_fmt);
            update.SetFormulas(progress.ID16, progress_fmt);
            update.Execute(page_a);

            var markup1 = new VA.Text.Markup.TextElement();

            markup1.AddField(VA.Text.Markup.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VA.Text.Markup.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VA.Text.Markup.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
Beispiel #5
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.Drawing.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 => GetPointAtRadius(origin, a, radius)).ToList();
            var    shapes             = centers.Select(p => draw_leaf(page, p)).ToList();
            var    angles_as_formulas = angles.Select(a => a.ToString()).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

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

            var update = new VA.ShapeSheet.Update();
            var format = new VA.Shapes.FormatCells();
            var xfrm   = new VA.Shapes.XFormCells();

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

                xfrm.Angle              = angles_as_formulas[i];
                format.FillForegnd      = color_formulas[i];
                format.LineWeight       = 0;
                format.LinePattern      = 0;
                format.FillForegndTrans = 0.5;

                update.SetFormulas(shapeid, xfrm);
                update.SetFormulas(shapeid, format);
            }

            update.Execute(page);
            VA.Pages.PageHelper.ResizeToFitContents(page, new VA.Drawing.Size(1.0, 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.Drawing.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 angles_as_formulas = angles.Select(a => a.ToString(CultureInfo.InvariantCulture)).ToList();

            var color_formulas = colors.Select(x => new VA.Drawing.ColorRGB(x).ToFormula()).ToList();

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

            var update = new VA.ShapeSheet.Update();
            var format = new VA.Shapes.FormatCells();
            var xfrm = new VA.Shapes.XFormCells();

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

                xfrm.Angle = angles_as_formulas[i];
                format.FillForegnd = color_formulas[i];
                format.LineWeight = 0;
                format.LinePattern = 0;
                format.FillForegndTrans = 0.5;

                update.SetFormulas(shapeid, xfrm);
                update.SetFormulas(shapeid, format);
            }

            update.Execute(page);
            VA.Pages.PageHelper.ResizeToFitContents(page, new VA.Drawing.Size(1.0, 1.0));
        }
Beispiel #7
0
        public void SetLock(IList <IVisio.Shape> target_shapes, VA.Shapes.LockCells lockcells)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var selection = this.Client.Selection.Get();
            var shapeids  = selection.GetIDs();
            var update    = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.VisioApplication;

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
Beispiel #8
0
        private static void TestResize(IVisio.Document doc,
                                       VA.Drawing.Size bottomleft_margin,
                                       VA.Drawing.Size upperright_margin,
                                       VA.Drawing.Size shape_size,
                                       VA.Drawing.Size padding_size,
                                       double expected_pinx,
                                       double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();

            pagecells.PageTopMargin    = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin   = bottomleft_margin.Width;
            pagecells.PageRightMargin  = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();

            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);


            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5 + shape_size.Height);

            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);

            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
Beispiel #9
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            VACONTROL.ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }


            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = String.Format("Controls.Row_{0}", row + 1);
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = String.Format("Controls.Row_{0}.Y", row + 1);
            }

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return(row);
        }
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page = this.client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
Beispiel #11
0
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells cp)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            if (!cp.X.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an X Formula");
            }

            if (!cp.Y.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an Y Formula");
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(cp, n);
            update.Execute(shape);

            return(n);
        }
        private static void TestResize(IVisio.Document doc, 
            VA.Drawing.Size bottomleft_margin, 
            VA.Drawing.Size upperright_margin, 
            VA.Drawing.Size shape_size, 
            VA.Drawing.Size padding_size,  
            double expected_pinx, 
            double expected_piny)
        {
            var page = doc.Pages.Add();

            var pagecells = new VA.Pages.PageCells();
            pagecells.PageTopMargin = upperright_margin.Height;
            pagecells.PageBottomMargin = bottomleft_margin.Height;
            pagecells.PageLeftMargin = bottomleft_margin.Width;
            pagecells.PageRightMargin = upperright_margin.Width;

            var pageupdate = new VA.ShapeSheet.Update();
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(page.PageSheet);

            var shape = page.DrawRectangle(5, 5, 5 + shape_size.Width, 5+shape_size.Height);
            page.ResizeToFitContents(padding_size);
            var xform = VA.Shapes.XFormCells.GetCells(shape);
            AssertVA.AreEqual(expected_pinx, expected_piny, xform.Pin(), 0.1);
            page.Delete(0);
        }
Beispiel #13
0
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Drawing.Size(this.BorderWidth, this.BorderWidth);
                this.Client.Page.ResizeToFitContents(bordersize, true);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page      = this.Client.Application.Get().ActivePage;
                var pagecells = VisioAutomation.Pages.PageCells.GetCells(page.PageSheet);

                var newpagecells = new VisioAutomation.Pages.PageCells();

                if (this.Width > 0)
                {
                    newpagecells.PageWidth = this.Width;
                }

                if (this.Height > 0)
                {
                    newpagecells.PageHeight = this.Height;
                }

                var update = new VisioAutomation.ShapeSheet.Update();
                update.SetFormulas(newpagecells);
                update.BlastGuards = true;
                update.Execute(page);
            }
        }
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells cp)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            if (!cp.X.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an X Formula");
            }

            if (!cp.Y.Formula.HasValue)
            {
                throw new System.ArgumentException("Must provide an Y Formula");
            }

            var n = shape.AddRow((short)IVisio.VisSectionIndices.visSectionConnectionPts,
                                 (short)IVisio.VisRowIndices.visRowLast,
                                 (short)IVisio.VisRowTags.visTagCnnctPt);

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(cp,n);
            update.Execute(shape);

            return n;
        }
        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.FormatCells();
            background_fmt.FillForegnd= "rgb(240,240,240)";
            background_fmt.LineColor = "rgb(100,100,100)";


            var progress_fmt = new VA.Shapes.FormatCells();
            progress_fmt.FillForegnd = "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 xform = new VA.Shapes.XFormCells();
            xform.PinX = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname);
            xform.PinY = string.Format("GUARD({0}!PinY)", bkname);
            xform.Width = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname);
            xform.Height = string.Format("GUARD({0}!Height)", bkname); 

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(progress.ID16, xform);
            update.SetFormulas(progress.ID16, background_fmt);
            update.SetFormulas(progress.ID16, progress_fmt);
            update.Execute(page_a);

            var markup1 = new VA.Text.Markup.TextElement();
            markup1.AddField(VA.Text.Markup.FieldConstants.PageName);
            markup1.AddText(" (");
            markup1.AddField(VA.Text.Markup.FieldConstants.PageNumber);
            markup1.AddText(" of ");
            markup1.AddField(VA.Text.Markup.FieldConstants.NumberOfPages);
            markup1.AddText(") ");
            markup1.SetText(group);
        }
        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.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.Grid.RowDirection.BottomToTop;

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

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

            update.Execute(page);

            var bordersize = new VA.Drawing.Size(1,1);
            page.ResizeToFitContents(bordersize);
        }
Beispiel #17
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("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 VA.Application.PerfScope(app, PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth  = this.Size.Value.Width;
                }

                var update = new VA.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();
                    }
                }
            }
        }
Beispiel #18
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new VA.Pages.PageCells();
            this.SetPageCells(pagecells);

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;
            update.Execute(pagesheet);
            page.Layout();
        }
Beispiel #19
0
        private static void SetSize(IVisio.Page page, VA.Drawing.Size size)
        {
            var page_cells = new VA.Pages.PageCells();

            page_cells.PageHeight = size.Height;
            page_cells.PageWidth  = size.Width;
            var pageupdate = new VA.ShapeSheet.Update();

            pageupdate.SetFormulas(page_cells);
            pageupdate.Execute(page.PageSheet);
        }
Beispiel #20
0
        private static void update_xfrms(IVisio.Page page, IList <int> shapeids, IList <VA.Shapes.XFormCells> xfrms)
        {
            var update = new VA.ShapeSheet.Update();

            for (int i = 0; i < shapeids.Count; i++)
            {
                var shape_id = shapeids[i];
                var xfrm     = xfrms[i];
                update.SetFormulas((short)shape_id, xfrm);
            }
            update.Execute(page);
        }
Beispiel #21
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new VA.Pages.PageCells();

            this.SetPageCells(pagecells);

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;

            update.Execute(pagesheet);
            page.Layout();
        }
        public void Page_Query()
        {
            var page1 = this.GetNewPage(new VA.Drawing.Size(4, 3));
            var pagecells = VA.Pages.PageCells.GetCells(page1.PageSheet);
            Assert.AreEqual(new VA.Drawing.Size(4, 3), new VA.Drawing.Size(pagecells.PageWidth.Result,pagecells.PageHeight.Result));

            // Double each side
            pagecells.PageWidth = pagecells.PageWidth.Result * 2.0;
            pagecells.PageHeight = pagecells.PageHeight.Result * 2.0;

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(pagecells);
            update.Execute(page1.PageSheet);

            var pagecells2 = VA.Pages.PageCells.GetCells(page1.PageSheet);
            Assert.AreEqual(new VA.Drawing.Size(8, 6), new VA.Drawing.Size(pagecells2.PageWidth.Result, pagecells2.PageHeight.Result));
            page1.Delete(0);
        }
Beispiel #23
0
        public void Page_Query()
        {
            var page1     = GetNewPage(new VA.Drawing.Size(4, 3));
            var pagecells = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual(new VA.Drawing.Size(4, 3), new VA.Drawing.Size(pagecells.PageWidth.Result, pagecells.PageHeight.Result));

            // Double each side
            pagecells.PageWidth  = pagecells.PageWidth.Result * 2.0;
            pagecells.PageHeight = pagecells.PageHeight.Result * 2.0;

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(pagecells);
            update.Execute(page1.PageSheet);

            var pagecells2 = VA.Pages.PageCells.GetCells(page1.PageSheet);

            Assert.AreEqual(new VA.Drawing.Size(8, 6), new VA.Drawing.Size(pagecells2.PageWidth.Result, pagecells2.PageHeight.Result));
            page1.Delete(0);
        }
Beispiel #24
0
        public void Set(IList <IVisio.Shape> target_shapes, VA.Shapes.FormatCells format)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            var update   = new VA.ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

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

            update.Execute(this.Client.VisioApplication.ActivePage);
        }
Beispiel #25
0
        private static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IList <VA.Drawing.Rectangle> rects)
        {
            var points   = rects.Select(r => r.Center).ToList();
            var shapeids = VA.Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new VA.Shapes.XFormCells();

            var update = new VA.ShapeSheet.Update(points.Count * 2);

            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width  = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return(shapeids);
        }
Beispiel #26
0
        private void buttonSetFillGradient_Click(object sender, System.EventArgs e)
        {
            var client    = VisioPowerToolsAddIn.Client;
            var selection = client.Selection.Get();

            if (selection.Count < 1)
            {
                return;
            }

            var format = new VA.Shapes.FormatCells();

            format.FillPattern          = (int)this.fillGradient1.FillDef.FillPattern;
            format.FillForegnd          = VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.ForegroundColor);
            format.FillBkgnd            = VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.BackgroundColor);
            format.FillForegndTrans     = this.fillGradient1.FillDef.ForegroundTransparency / 100.0;
            format.FillBkgndTrans       = this.fillGradient1.FillDef.BackgroundTransparency / 100.0;
            format.ShdwPattern          = (int)this.fillGradient1.ShadowDef.FillPattern;
            format.ShdwForegnd          = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.ForegroundColor);
            format.ShdwBkgnd            = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.BackgroundColor);
            format.ShdwForegndTrans     = this.fillGradient1.ShadowDef.ForegroundTransparency / 100.0;
            format.ShdwBkgndTrans       = this.fillGradient1.ShadowDef.BackgroundTransparency / 100.0;
            format.ShapeShdwOffsetX     = 0.0;
            format.ShapeShdwOffsetY     = 0.0;
            format.ShapeShdwScaleFactor = 1.0;
            format.ShapeShdwType        = 5;


            var update   = new VA.ShapeSheet.Update();
            var shapes   = client.Selection.GetShapes().ToList();
            var shapeids = shapes.Select(s => s.ID).ToList();

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

            update.Execute(client.VisioApplication.ActivePage);
        }
        private void buttonSetFillGradient_Click(object sender, System.EventArgs e)
        {
            var client = VisioPowerToolsAddIn.Client;
            var selection = client.Selection.Get();
            if (selection.Count < 1)
            {
                return;
            }

            var format = new VA.Shapes.FormatCells();
            format.FillPattern = (int) this.fillGradient1.FillDef.FillPattern;
            format.FillForegnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.ForegroundColor);
            format.FillBkgnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.FillDef.BackgroundColor);
            format.FillForegndTrans= this.fillGradient1.FillDef.ForegroundTransparency/100.0;
            format.FillBkgndTrans= this.fillGradient1.FillDef.BackgroundTransparency / 100.0;
            format.ShdwPattern= (int) this.fillGradient1.ShadowDef.FillPattern;
            format.ShdwForegnd= VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.ForegroundColor);
            format.ShdwBkgnd = VA.Convert.ColorToFormulaRGB(this.fillGradient1.ShadowDef.BackgroundColor);
            format.ShdwForegndTrans = this.fillGradient1.ShadowDef.ForegroundTransparency/100.0;
            format.ShdwBkgndTrans= this.fillGradient1.ShadowDef.BackgroundTransparency/100.0;
            format.ShapeShdwOffsetX = 0.0;
            format.ShapeShdwOffsetY = 0.0;
            format.ShapeShdwScaleFactor = 1.0;
            format.ShapeShdwType= 5;

            var update = new VA.ShapeSheet.Update();
            var shapes = client.Selection.GetShapes().ToList();
            var shapeids = shapes.Select(s => s.ID).ToList();

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

            update.Execute(client.VisioApplication.ActivePage);
        }
Beispiel #28
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.Drawing.ColorRGB(0xffdddd);
            var color2 = new VA.Drawing.ColorRGB(0x00ffff);

            var format = new VA.Shapes.FormatCells();

            var update = new VA.ShapeSheet.Update();

            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;
                update.SetFormulas(shapeid, format);

                n++;
            }

            update.Execute(page);

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

            page.ResizeToFitContents(bordersize);
        }
 private static void SetSize(IVisio.Page page, VA.Drawing.Size size)
 {
     var page_cells = new VA.Pages.PageCells();
     page_cells.PageHeight = size.Height;
     page_cells.PageWidth = size.Width;
     var pageupdate = new VA.ShapeSheet.Update();
     pageupdate.SetFormulas(page_cells);
     pageupdate.Execute(page.PageSheet);
 }
        private static short[] DropManyU(
            IVisio.Page page,
            IList<IVisio.Master> masters,
            IList<VA.Drawing.Rectangle> rects)
        {
            var points = rects.Select(r => r.Center).ToList();
            var shapeids = VA.Pages.PageHelper.DropManyU(page, masters, points);

            var xfrm = new VA.Shapes.XFormCells();

            var update = new VA.ShapeSheet.Update(points.Count*2);
            for (int i = 0; i < rects.Count(); i++)
            {
                xfrm.Width = rects[i].Width;
                xfrm.Height = rects[i].Height;
                update.SetFormulas(shapeids[i], xfrm);
            }
            update.Execute(page);

            return shapeids;
        }
        public void ToogleCase(IList<IVisio.Shape> target_shapes)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication, "Toggle Shape Text Case"))
            {
                var shapeids = shapes.Select(s => s.ID).ToList();

                var page = this.Client.VisioApplication.ActivePage;
                // Store all the formatting
                var formats = VA.Text.TextFormat.GetFormat(page, shapeids);

                // Change the text - this will wipe out all the character and paragraph formatting
                foreach (var shape in shapes)
                {
                    string t = shape.Text;
                    if (t.Length < 1)
                    {
                        continue;
                    }
                    shape.Text = TextCommandsUtil.toggle_case(t);
                }

                // Now restore all the formatting - based on any initial formatting from the text

                var update = new VA.ShapeSheet.Update();
                for (int i = 0; i < shapes.Count; i++)
                {
                    var format = formats[i];

                    if (format.CharacterFormats.Count > 0)
                    {
                        var fmt = format.CharacterFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }

                    if (format.ParagraphFormats.Count > 0)
                    {
                        var fmt = format.ParagraphFormats[0];
                        update.SetFormulas((short)shapeids[i], fmt, 0);
                    }
                }

                update.Execute(page);
            }
        }
 private static void update_xfrms(IVisio.Page page, IList<int> shapeids, IList<VA.Shapes.XFormCells> xfrms)
 {
     var update = new VA.ShapeSheet.Update();
     for (int i = 0; i < shapeids.Count; i++)
     {
         var shape_id = shapeids[i];
         var xfrm = xfrms[i];
         update.SetFormulas((short)shape_id, xfrm);
     }
     update.Execute(page);
 }
Beispiel #33
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("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 VA.Application.PerfScope(app, PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth = this.Size.Value.Width;
                }

                var update = new VA.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 static int Set(
            IVisio.Shape shape,
            short row,
            VACONTROL.ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }

            if (!ctrl.XDynamics.Formula.HasValue)
            {
                ctrl.XDynamics = String.Format("Controls.Row_{0}", row + 1);
            }

            if (!ctrl.YDynamics.Formula.HasValue)
            {
                ctrl.YDynamics = String.Format("Controls.Row_{0}.Y", row + 1);
            }

            var update = new VA.ShapeSheet.Update();
            update.SetFormulas(ctrl, row);
            update.Execute(shape);

            return row;
        }
        public void SetLock(IList<IVisio.Shape> target_shapes, VA.Shapes.LockCells lockcells)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = GetTargetShapes(target_shapes);
            if (shapes.Count < 1)
            {
                return;
            }

            var selection = this.Client.Selection.Get();
            var shapeids = selection.GetIDs();
            var update = new VA.ShapeSheet.Update();

            foreach (int shapeid in shapeids)
            {
                update.SetFormulas((short)shapeid, lockcells);
            }

            var application = this.Client.VisioApplication;
            using (var undoscope = new VA.Application.UndoScope(this.Client.VisioApplication,"Set Shape Lock Properties"))
            {
                var active_page = application.ActivePage;
                update.Execute(active_page);
            }
        }
        public void Set(IList<IVisio.Shape> target_shapes, VA.Shapes.FormatCells format)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            var shapes = this.GetTargetShapes(target_shapes);

            if (shapes.Count<1)
            {
                return;
            }

            var update = new VA.ShapeSheet.Update();
            var shapeids = shapes.Select(s => s.ID).ToList();

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

            update.Execute(this.Client.VisioApplication.ActivePage);
        }
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            var app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException("src_page");
            }

            if (dest_page == null)
            {
                throw new System.ArgumentNullException("dest_page");
            }

            if (dest_page == src_page)
            {
                throw new VA.AutomationException("Destination Page cannot be Source Page");
            }

            if (src_page != app.ActivePage)
            {
                throw new VA.AutomationException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes=src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            var src_pagesheet = src_page.PageSheet;
            var pagecells = VA.Pages.PageCells.GetCells(src_pagesheet);

            // handle the dest page

            // first update all the page cells
            var dest_pagesheet = dest_page.PageSheet;
            var update = new VisioAutomation.ShapeSheet.Update();
            update.SetFormulas(pagecells);
            update.Execute(dest_pagesheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;

            // then paste any contents from the first page
            if (num_src_shapes>0)
            {
                dest_page.Paste(copy_paste_flags);
            }
        }
        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.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.Grid.RowDirection.BottomToTop;

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

            var fmtcells = new VA.Shapes.FormatCells();
            int i        = 0;
            var update   = new VA.ShapeSheet.Update();

            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;
                update.SetFormulas(shapeid, fmtcells);
                i++;
            }

            update.Execute(page);

            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.Drawing.ColorRGB(0xffdddd);
            var color2 = new VA.Drawing.ColorRGB(0x00ffff);

            var format = new VA.Shapes.FormatCells();

            var update = new VA.ShapeSheet.Update();

            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;
                update.SetFormulas(shapeid, format);

                n++;
            }

            update.Execute(page);

            var bordersize = new VA.Drawing.Size(1, 1);
            page.ResizeToFitContents(bordersize);
        }
Beispiel #40
0
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            var   app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException("src_page");
            }

            if (dest_page == null)
            {
                throw new System.ArgumentNullException("dest_page");
            }

            if (dest_page == src_page)
            {
                throw new VA.AutomationException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new VA.AutomationException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes  = src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            var src_pagesheet = src_page.PageSheet;
            var pagecells     = VA.Pages.PageCells.GetCells(src_pagesheet);


            // handle the dest page

            // first update all the page cells
            var dest_pagesheet = dest_page.PageSheet;
            var update         = new VisioAutomation.ShapeSheet.Update();

            update.SetFormulas(pagecells);
            update.Execute(dest_pagesheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;

            // then paste any contents from the first page
            if (num_src_shapes > 0)
            {
                dest_page.Paste(copy_paste_flags);
            }
        }