コード例 #1
0
        public void Scripting_Draw_AreaChart()
        {
            var pagesize = new VA.Geometry.Size(4, 4);
            var rect1    = new VA.Geometry.Rectangle(0, 0, 4, 4);
            var rect2    = new VA.Geometry.Rectangle(5, 0, 9, 4);
            var rect3    = new VA.Geometry.Rectangle(10, 0, 14, 4);
            var padding  = new VA.Geometry.Size(1.0, 1.0);

            var chart1 = new VisioAutomation.Models.Charting.AreaChart(rect1);

            chart1.DataPoints.Add(1.0);
            chart1.DataPoints.Add(2.0);
            chart1.DataPoints.Add(3.0);
            chart1.DataPoints.Add(4.0);

            var chart2 = new VisioAutomation.Models.Charting.AreaChart(rect2);

            chart2.DataPoints.Add(1.0);
            chart2.DataPoints.Add(2.0);
            chart2.DataPoints.Add(-3.0);
            chart2.DataPoints.Add(4.0);

            var chart3 = new VisioAutomation.Models.Charting.AreaChart(rect3);

            chart3.DataPoints.Add(-1.0);
            chart3.DataPoints.Add(-2.0);
            chart3.DataPoints.Add(-3.0);
            chart3.DataPoints.Add(-4.0);

            // Setup the Page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Charts
            client.Draw.AreaChart(chart1);
            client.Draw.AreaChart(chart2);
            client.Draw.AreaChart(chart3);
            client.Page.Get().ResizeToFitContents(padding);

            // Cleanup
            client.Document.Close(true);
        }
コード例 #2
0
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Page).ResolveToPages(this.Client);

            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Geometry.Size(this.BorderWidth, this.BorderHeight);
                this.Client.Page.ResizePageToFitContents(targetpages, bordersize);
                this.Client.View.SetZoomToObject(VisioScripting.TargetWindow.Auto, VisioScripting.Models.ZoomToObject.Page);
            }

            if (this.Width > 0 || this.Height > 0)
            {
                var page_format_cells = new VisioAutomation.Pages.PageFormatCells();

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

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

                this.Client.Page.SetPageFormatCells(targetpages, page_format_cells);
            }


            if (this.Orientation.HasValue)
            {
                this.Client.Page.SetPageOrientation(targetpages, this.Orientation.Value);
            }

            if (this.BackgroundPage != null)
            {
                this.Client.Page.SetPageBackground(targetpages, this.BackgroundPage);
            }

            if (this.LayoutStyle != null)
            {
                this.Client.Page.LayoutPage(targetpages, this.LayoutStyle);
            }
        }
コード例 #3
0
        public void Scripting_Draw_BarChart()
        {
            var pagesize   = new VA.Geometry.Size(4, 4);
            var rect1      = new VA.Geometry.Rectangle(0, 0, 4, 4);
            var rect2      = new VA.Geometry.Rectangle(5, 0, 9, 4);
            var rect3      = new VA.Geometry.Rectangle(10, 0, 14, 4);
            var bordersize = new VA.Geometry.Size(1.0, 1.0);

            var chart1 = new VisioAutomation.Models.Charting.BarChart(rect1);

            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(1.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(2.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(3.0));
            chart1.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(4.0));

            var chart2 = new VisioAutomation.Models.Charting.BarChart(rect2);

            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(1.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(2.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-3.0));
            chart2.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(4.0));

            var chart3 = new VisioAutomation.Models.Charting.BarChart(rect3);

            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-1.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-2.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-3.0));
            chart3.DataPoints.Add(new VisioAutomation.Models.Charting.DataPoint(-4.0));

            // Create the page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Charts
            client.Draw.BarChart(chart1);
            client.Draw.BarChart(chart2);
            client.Draw.BarChart(chart3);
            client.Page.ResizeToFitContents(bordersize, true);

            // Cleanup
            client.Document.Close(true);
        }
コード例 #4
0
        public void Scripting_Distribute_With_Spacing()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Document.New();
            client.Page.New(pagesize, false);

            var size1 = new VA.Geometry.Size(0.5, 0.5);
            var size2 = new VA.Geometry.Size(1.0, 1.0);
            var size3 = new VA.Geometry.Size(1.5, 1.5);

            var r1 = new VA.Geometry.Rectangle(new VA.Geometry.Point(1, 1), size1);
            var r2 = new VA.Geometry.Rectangle(new VA.Geometry.Point(2, 2), size2);
            var r3 = new VA.Geometry.Rectangle(new VA.Geometry.Point(4, 4), size3);

            var s1 = client.Draw.Rectangle(r1);
            var s2 = client.Draw.Rectangle(r2);
            var s3 = client.Draw.Rectangle(r3);

            client.Selection.SelectNone();
            client.Selection.Select(s1);
            client.Selection.Select(s2);
            client.Selection.Select(s3);

            var targets = new VisioScripting.Models.TargetShapes();

            client.Distribute.DistributeOnAxis(targets, VisioScripting.Models.Axis.XAxis, 0.25);
            client.Distribute.DistributeOnAxis(targets, VisioScripting.Models.Axis.YAxis, 1.0);

            var shapeids      = new[] { s1.ID, s2.ID, s3.ID };
            var out_xfrms     = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.Get(), shapeids, VA.ShapeSheet.CellValueType.Result);
            var out_positions = out_xfrms.Select(xfrm => TestExtensions.ToPoint(xfrm.PinX.Value, xfrm.PinY.Value)).ToArray();

            Assert.AreEqual(1.25, out_positions[0].X);
            Assert.AreEqual(1.25, out_positions[0].Y);
            Assert.AreEqual(2.25, out_positions[1].X);
            Assert.AreEqual(3.00, out_positions[1].Y);
            Assert.AreEqual(3.75, out_positions[2].X);
            Assert.AreEqual(5.25, out_positions[2].Y);

            client.Document.Close(true);
        }
コード例 #5
0
        public static VisioAutomation.Geometry.Size GetPageSize(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var query      = new CellQuery();
            var col_height = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, "PageHeight");
            var col_width  = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, "PageWidth");

            var    cellqueryresults = query.GetResults <double>(page.PageSheet);
            var    row    = cellqueryresults[0];
            double height = row[col_height];
            double width  = row[col_width];
            var    s      = new VisioAutomation.Geometry.Size(width, height);

            return(s);
        }
コード例 #6
0
        public IVisio.Page GetNewPage(VisioAutomation.Geometry.Size s)
        {
            var app       = this.GetVisioApplication();
            var documents = app.Documents;

            if (documents.Count < 1)
            {
                var doc = documents.Add(string.Empty);
                doc.AutoRecover = false;
            }
            var active_document = app.ActiveDocument;
            var pages           = active_document.Pages;
            var page            = pages.Add();

            page.Background = 0;
            SetPageSize(page, s);

            return(page);
        }
コード例 #7
0
        public void Scripting_Test_Resize_Application_Window2()
        {
            var client    = this.GetScriptingClient();
            var page_size = new VisioAutomation.Geometry.Size(10, 5);
            var doc       = client.Document.NewDocument(page_size);

            var page    = client.Page.GetActivePage();
            var page_tp = new VisioScripting.Models.TargetPages(page);

            var pagesize = client.Page.GetPageSize(page_tp);

            Assert.AreEqual(10.0, pagesize.Width);
            Assert.AreEqual(5.0, pagesize.Height);
            Assert.AreEqual(0, client.Selection.GetActiveSelection().Count);
            client.Draw.DrawRectangle(1, 1, 2, 2);
            Assert.AreEqual(1, client.Selection.GetActiveSelection().Count);

            client.Document.CloseActiveDocument(true);
        }
コード例 #8
0
        public void Scripting_Test_Resize_Application_Window2()
        {
            var client    = this.GetScriptingClient();
            var page_size = new VisioAutomation.Geometry.Size(10, 5);
            var doc       = client.Document.NewDocument(page_size);

            var pagesizes = client.Page.GetPageSize(VisioScripting.TargetPages.Auto);

            Assert.AreEqual(10.0, pagesizes[0].Width);
            Assert.AreEqual(5.0, pagesizes[0].Height);

            Assert.AreEqual(0, client.Selection.GetSelection(VisioScripting.TargetWindow.Auto).Count);


            client.Draw.DrawRectangle(VisioScripting.TargetPage.Auto, 1, 1, 2, 2);
            Assert.AreEqual(1, client.Selection.GetSelection(VisioScripting.TargetWindow.Auto).Count);

            client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto);
        }
コード例 #9
0
        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.Geometry.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.Geometry.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.Geometry.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.Geometry.Size(1, 1);

            page.ResizeToFitContents(bordersize);
        }
コード例 #10
0
        public static void OrgChart()
        {
            // This creates a new document
            var orgchart = new OCMODEL.OrgChartDocument();

            var bob   = new OCMODEL.Node("Bob");
            var ted   = new OCMODEL.Node("Ted");
            var alice = new OCMODEL.Node("Alice");

            bob.Children.Add(ted);
            bob.Children.Add(alice);

            orgchart.OrgCharts.Add(bob);

            orgchart.Render(SampleEnvironment.Application);

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

            SampleEnvironment.Application.ActivePage.ResizeToFitContents(bordersize);
        }
コード例 #11
0
        public void Scripting_Draw_PieSlice()
        {
            var    pagesize    = new VA.Geometry.Size(4, 4);
            var    center      = new VA.Geometry.Point(2, 2);
            double radius      = 1.0;
            double start_angle = 0;
            double end_angle   = Math.PI;

            // Create the page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Shape
            var shape = client.Draw.PieSlice(center, radius, start_angle, end_angle);

            // Cleanup
            client.Document.Close(true);
        }
コード例 #12
0
        public VisioAutomation.Geometry.Size GetSize()
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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


            var query      = new CellQuery();
            var col_height = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageHeight));
            var col_width  = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageWidth));

            var    results = query.GetResults <double>(active_page.PageSheet);
            double height  = results.Cells[col_height];
            double width   = results.Cells[col_width];
            var    s       = new VisioAutomation.Geometry.Size(width, height);

            return(s);
        }
コード例 #13
0
        public IVisio.Document NewDocumentFromTemplate(VisioAutomation.Geometry.Size size, string template)
        {
            var cmdtarget = this._client.GetCommandTargetApplication();

            var doc       = this.NewDocumentFromTemplate(template);
            var pagecells = new VisioAutomation.Pages.PageFormatCells();

            pagecells.Width  = size.Width;
            pagecells.Height = size.Height;

            var pages = doc.Pages;
            var page  = pages[1];

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            writer.SetValues(pagecells);
            writer.Commit(page.PageSheet, CellValueType.Formula);

            return(doc);
        }
コード例 #14
0
        public void Page_ResizeBorder()
        {
            var doc       = this.GetNewDoc();
            var shapesize = new VisioAutomation.Geometry.Size(1, 2);
            var border1   = new VisioAutomation.Geometry.Size(0, 0);
            var border2   = new VA.Geometry.Size(3, 4);

            VerifyPageSizeToFit(doc, new VA.Geometry.Size(1, 1), new VA.Geometry.Size(1, 1), shapesize, border1, 1.5, 2);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 0), new VA.Geometry.Size(0, 0), shapesize, border1, 0.5, 1);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(1, 0), new VA.Geometry.Size(0, 0), shapesize, border1, 1.5, 1);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 1), new VA.Geometry.Size(0, 0), shapesize, border1, 0.5, 2);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 0), new VA.Geometry.Size(1, 0), shapesize, border1, 0.5, 1);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 0), new VA.Geometry.Size(0, 1), shapesize, border1, 0.5, 1);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(1, 1), new VA.Geometry.Size(1, 1), shapesize, border2, 4.5, 6);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(1, 0), new VA.Geometry.Size(0, 0), shapesize, border2, 4, 5);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 1), new VA.Geometry.Size(0, 0), shapesize, border2, 3.5, 5.5);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 0), new VA.Geometry.Size(1, 0), shapesize, border2, 4, 5);
            VerifyPageSizeToFit(doc, new VA.Geometry.Size(0, 0), new VA.Geometry.Size(0, 1), shapesize, border2, 3.5, 5.5);
            doc.Close(true);
        }
コード例 #15
0
        public VisioAutomation.Geometry.Size GetPageSize(TargetPages targetpages)
        {
            targetpages = targetpages.Resolve(this._client);

            if (targetpages.Pages.Count < 1)
            {
                throw new System.ArgumentException("No pages found");
            }

            var query      = new VisioAutomation.ShapeSheet.Query.CellQuery();
            var col_height = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageHeight));
            var col_width  = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageWidth));

            var    cellqueryresult = query.GetResults <double>(targetpages.Pages[0].PageSheet);
            var    row             = cellqueryresult[0];
            double height          = row[col_height];
            double width           = row[col_width];
            var    s = new VisioAutomation.Geometry.Size(width, height);

            return(s);
        }
コード例 #16
0
ファイル: Util.cs プロジェクト: xiaoxiongnpu/VisioAutomation
        public static void Render(BoxLayout layout, IVisio.Document doc)
        {
            layout.PerformLayout();
            var page1 = doc.Pages.Add();
            // and tinker with it
            // render
            var nodes = layout.Nodes.ToList();

            foreach (var node in nodes)
            {
                var shape = page1.DrawRectangle(node.Rectangle);
                node.Data = shape;
            }

            var root_shape = (IVisio.Shape)layout.Root.Data;

            root_shape.CellsU["FillForegnd"].FormulaForceU = "rgb(240,240,240)";
            var margin = new VisioAutomation.Geometry.Size(0.5, 0.5);

            page1.ResizeToFitContents(margin);
        }
コード例 #17
0
        public GridLayout(int cols, int rows, VisioAutomation.Geometry.Size cellsize, IVisio.Master master)
        {
            this.ColumnDirection = ColumnDirection.LeftToRight;
            this.RowDirection    = RowDirection.BottomToTop;
            this.CellSpacing     = new VisioAutomation.Geometry.Size(0.5, 0.25);
            this.ColumnCount     = cols;
            this.RowCount        = rows;

            // initialize the sizes for the rows and columns
            this.Rows = new List <Row>(this.RowCount);
            foreach (int row in Enumerable.Range(0, this.RowCount))
            {
                var r = new Row();
                r.Height = cellsize.Height;
                this.Rows.Add(r);
            }

            this.Columns = new List <Column>(this.ColumnCount);
            foreach (int col in Enumerable.Range(0, this.ColumnCount))
            {
                var c = new Column();
                c.Width = cellsize.Width;
                this.Columns.Add(c);
            }

            // Create the nodes
            this._nodes = new Node[this.RowCount, this.ColumnCount];
            foreach (int row in Enumerable.Range(0, this.RowCount))
            {
                foreach (int col in Enumerable.Range(0, this.ColumnCount))
                {
                    var node = new Node();
                    node.Column           = col;
                    node.Row              = row;
                    node.Master           = master;
                    node.Draw             = true;
                    this._nodes[row, col] = node;
                }
            }
        }
コード例 #18
0
        public void Scripting_Page_Navigation()
        {
            var page_size = new VisioAutomation.Geometry.Size(8.5, 11);
            var client    = this.GetScriptingClient();
            var doc       = client.Document.New(page_size);

            var page1 = client.Page.Get();

            client.Page.New(page_size, false);
            var page2 = client.Page.Get();

            client.Page.New(page_size, false);
            var page3 = client.Page.Get();

            Assert.AreEqual(3, doc.Pages.Count);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(PageDirection.First);
            Assert.AreEqual(page1, client.Page.Get());
            client.Page.GoTo(PageDirection.Last);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(PageDirection.Previous);
            Assert.AreEqual(page2, client.Page.Get());
            client.Page.GoTo(PageDirection.Next);
            Assert.AreEqual(page3, client.Page.Get());

            // move to last and try to go to next page
            client.Page.GoTo(PageDirection.Last);
            Assert.AreEqual(page3, client.Page.Get());
            client.Page.GoTo(PageDirection.Next);
            Assert.AreEqual(page3, client.Page.Get());

            // move to first and try to go to previous page
            client.Page.GoTo(PageDirection.First);
            Assert.AreEqual(page1, client.Page.Get());
            client.Page.GoTo(PageDirection.Previous);
            Assert.AreEqual(page1, client.Page.Get());

            doc.Close(true);
        }
コード例 #19
0
        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.NewDocument();
            client.Page.NewPage(pagesize, false);

            // Find the stencil and master
            var stencildoc   = client.Document.OpenStencilDocument("basic_u.vss");
            var stencil_tdoc = new VisioScripting.TargetDocument(stencildoc);
            var master       = client.Master.GetMaster(stencil_tdoc, "Rectangle");

            // Draw the grid
            var page = client.Page.GetActivePage();
            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.ToList();
            int total_shapes_actual = shapes.Count;

            Assert.AreEqual(total_shapes_expected, total_shapes_actual);

            // Cleanup
            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
コード例 #20
0
        public void Scripting_Distribute()
        {
            var client   = this.GetScriptingClient();
            var pagesize = new VA.Geometry.Size(4, 4);

            client.Document.NewDocument();
            client.Page.NewPage(pagesize, false);

            var size1 = new VA.Geometry.Size(0.5, 0.5);
            var size2 = new VA.Geometry.Size(1.0, 1.0);
            var size3 = new VA.Geometry.Size(1.5, 1.5);

            var r1 = new VA.Geometry.Rectangle(new VA.Geometry.Point(1, 1), size1);
            var r2 = new VA.Geometry.Rectangle(new VA.Geometry.Point(2, 2), size2);
            var r3 = new VA.Geometry.Rectangle(new VA.Geometry.Point(4, 4), size3);

            var s1 = client.Draw.DrawRectangle(r1);
            var s2 = client.Draw.DrawRectangle(r2);
            var s3 = client.Draw.DrawRectangle(r3);

            client.Selection.SelectNone();
            client.Selection.SelectShapesById(s1);
            client.Selection.SelectShapesById(s2);
            client.Selection.SelectShapesById(s3);

            var targetshapes = new VisioScripting.TargetShapes();

            client.Distribute.DistributeShapesHorizontal(targetshapes, VisioScripting.Models.AlignmentHorizontal.Center);

            var shapes   = new[] { s1, s2, s3 };
            var shapeids = shapes.Select(s => (int)s.ID16).ToList();

            VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Formula);

            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
コード例 #21
0
        public void Scripting_Nudge2()
        {
            var client = this.GetScriptingClient();

            client.Document.NewDocument();
            client.Page.NewPage(new VA.Geometry.Size(4, 4), false);

            var size1 = new VA.Geometry.Size(0.5, 0.5);
            var size2 = new VA.Geometry.Size(1.0, 1.0);
            var size3 = new VA.Geometry.Size(1.5, 1.5);

            var r1 = new VA.Geometry.Rectangle(new VA.Geometry.Point(1, 1), size1);
            var r2 = new VA.Geometry.Rectangle(new VA.Geometry.Point(2, 2), size2);
            var r3 = new VA.Geometry.Rectangle(new VA.Geometry.Point(4, 4), size3);

            var s1 = client.Draw.DrawRectangle(r1);
            var s2 = client.Draw.DrawRectangle(r2);
            var s3 = client.Draw.DrawRectangle(r3);

            client.Selection.SelectNone();
            client.Selection.SelectShapesById(s1);
            client.Selection.SelectShapesById(s2);
            client.Selection.SelectShapesById(s3);

            client.Arrange.NudgeSelection(0.50, -0.25);

            var shapes   = new[] { s1, s2, s3 };
            var shapeids = shapes.Select(s => (int)s.ID16).ToList();
            var xforms   = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Result);

            AssertUtil.AreEqual((1.75, 1), xforms[0].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((3, 2.25), xforms[1].GetPinPosResult(), 0.00001);
            AssertUtil.AreEqual((5.25, 4.5), xforms[2].GetPinPosResult(), 0.00001);
            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
コード例 #22
0
        public void Dom_DrawSimpleShape()
        {
            // Create the doc
            var page_node = new VADOM.Page();
            var vrect1    = new VADOM.Rectangle(1, 1, 9, 9);

            vrect1.Text = new VisioAutomation.Models.Text.Element("HELLO WORLD");
            vrect1.Cells.FillForeground = "rgb(255,0,0)";
            page_node.Shapes.Add(vrect1);

            // Render it
            var app = this.GetVisioApplication();
            var doc = this.GetNewDoc();

            this.pagesize = new VA.Geometry.Size(10, 10);
            VisioAutomationTest.SetPageSize(app.ActivePage, this.pagesize);
            var page = page_node.Render(app.ActiveDocument);

            // Verify
            Assert.IsNotNull(vrect1.VisioShape);
            Assert.AreEqual("HELLO WORLD", vrect1.VisioShape.Text);

            app.ActiveDocument.Close(true);
        }
コード例 #23
0
        public void Scripting_Draw_BezierPolyLine_0()
        {
            var points = new[]
            {
                new VA.Geometry.Point(0, 0),
                new VA.Geometry.Point(2, 0.5),
                new VA.Geometry.Point(2, 2),
                new VA.Geometry.Point(3, 0.5)
            };
            var pagesize = new VA.Geometry.Size(4, 4);

            // Create the Page
            var client = this.GetScriptingClient();

            client.Document.NewDocument();
            client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false);

            // Draw the Shapes
            var shape_bezier   = client.Draw.DrawBezier(VisioScripting.TargetPage.Auto, points);
            var shape_polyline = client.Draw.DrawPolyLine(VisioScripting.TargetPage.Auto, points);

            // Cleanup
            client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto);
        }
コード例 #24
0
        public void Scripting_Draw_BezierPolyLine_0()
        {
            var points = new[]
            {
                new VA.Geometry.Point(0, 0),
                new VA.Geometry.Point(2, 0.5),
                new VA.Geometry.Point(2, 2),
                new VA.Geometry.Point(3, 0.5)
            };
            var pagesize = new VA.Geometry.Size(4, 4);

            // Create the Page
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(pagesize, false);

            // Draw the Shapes
            var shape_bezier   = client.Draw.Bezier(points);
            var shape_polyline = client.Draw.PolyLine(points);

            // Cleanup
            client.Document.Close(true);
        }
コード例 #25
0
 private VA.Geometry.Size ToMGCoordinates(VA.Geometry.Size s)
 {
     return(s.Multiply(this.ScaleToMsagl, this.ScaleToMsagl));
 }
コード例 #26
0
        public IVisio.Document DrawNamespacesAndClasses(IList <Type> types_)
        {
            this._client.Application.AssertApplicationAvailable();

            string segoeui_fontname      = "Segoe UI";
            string segoeuilight_fontname = "Segoe UI Light";
            string def_linecolor         = "rgb(180,180,180)";
            string def_shape_fill        = "rgb(245,245,245)";
            string template = null;

            var page_size         = new VisioAutomation.Geometry.Size(8.5, 11);
            var doc               = this._client.Document.New(page_size, template);
            var fonts             = doc.Fonts;
            var font_segoe        = fonts[segoeui_fontname];
            var font_segoelight   = fonts[segoeuilight_fontname];
            int fontid_segoe      = font_segoe.ID16;
            int fontid_segoelight = font_segoelight.ID16;

            var types = types_.Select(t => new TypeInfo(t));

            var pathbuilder = new PathTreeBuilder();

            foreach (var type in types)
            {
                pathbuilder.Add(type.Type.Namespace);
            }

            var namespaces = pathbuilder.GetPaths();

            var tree_layout = new VisioAutomation.Models.Layouts.Tree.Drawing();

            tree_layout.LayoutOptions.Direction     = LayoutDirection.Down;
            tree_layout.LayoutOptions.ConnectorType = ConnectorType.PolyLine;
            var ns_node_map     = new Dictionary <string, Node>(namespaces.Count);
            var node_to_nslabel = new Dictionary <Node, string>(namespaces.Count);

            // create nodes for every namespace
            foreach (string ns in namespaces)
            {
                string label             = ns;
                int    index_of_last_sep = ns.LastIndexOf(pathbuilder.Separator, StringComparison.Ordinal);
                if (index_of_last_sep > 0)
                {
                    label = ns.Substring(index_of_last_sep + 1);
                }

                string ns1 = ns;
                var    types_in_namespace = types.Where(t => t.Type.Namespace == ns1)
                                            .OrderBy(t => t.Type.Name)
                                            .Select(t => t.Label);
                var node = new Node(ns);
                node.Size = new VisioAutomation.Geometry.Size(2.0, (0.15) * (1 + 2 + types_in_namespace.Count()));


                var markup = new VisioAutomation.Models.Text.Element();
                var m1     = markup.AddElement(label + "\n");
                m1.CharacterFormatting.Font  = fontid_segoe;
                m1.CharacterFormatting.Size  = "12.0pt";
                m1.CharacterFormatting.Style = "1"; // Bold
                var m2 = markup.AddElement();
                m2.CharacterFormatting.Font = fontid_segoe;
                m2.CharacterFormatting.Size = "8.0pt";
                m2.AddText(string.Join("\n", types_in_namespace));

                node.Text = markup;

                ns_node_map[ns]       = node;
                node_to_nslabel[node] = label;
            }

            // add children to nodes
            foreach (string ns in namespaces)
            {
                var parent_ns = pathbuilder.PathToParentPath[ns];

                if (parent_ns != null)
                {
                    // the current namespace has a parent
                    var parent_node = ns_node_map[parent_ns];
                    var child_node  = ns_node_map[ns];
                    parent_node.Children.Add(child_node);
                }
                else
                {
                    // that means this namespace is a root, forget about it
                }
            }

            if (pathbuilder.Roots.Count == 0)
            {
            }
            else if (pathbuilder.Roots.Count == 1)
            {
                // when there is exactly one root namespace, then that node will be the tree's root node
                var first_root = pathbuilder.Roots[0];
                var root_n     = ns_node_map[first_root];
                tree_layout.Root = root_n;
            }
            else
            {
                // if there are multiple root namespaces, inject an empty placeholder root
                var root_n = new Node();
                tree_layout.Root = root_n;

                foreach (var root_ns in pathbuilder.Roots)
                {
                    var node = ns_node_map[root_ns];
                    tree_layout.Root.Children.Add(node);
                }
            }

            // format the shapes
            foreach (var node in tree_layout.Nodes)
            {
                if (node.Cells == null)
                {
                    node.Cells = new ShapeCells();
                }
                node.Cells.FillForeground = def_shape_fill;
                //node.ShapeCells.LineWeight = "0";
                //node.ShapeCells.LinePattern = "0";
                node.Cells.LineColor              = def_linecolor;
                node.Cells.ParaHorizontalAlign    = "0";
                node.Cells.TextBlockVerticalAlign = "0";
            }

            var cxn_cells = new ShapeCells();

            cxn_cells.LineColor = def_linecolor;
            tree_layout.LayoutOptions.ConnectorCells = cxn_cells;
            tree_layout.Render(doc.Application.ActivePage);

            DeveloperCommands.hide_ui_stuff(doc);

            return(doc);
        }
コード例 #27
0
        public static void BoxLayout_TwoLevelGrouping()
        {
            int num_types      = 10;
            int max_properties = 50;

            var types = typeof(UserDefinedCellCells).Assembly.GetExportedTypes().Take(num_types).ToList();

            var data = new List <string[]>();

            foreach (var type in types)
            {
                var properties = type.GetProperties().Take(max_properties).ToList();
                foreach (var property in properties)
                {
                    var item = new[] { type.Name, property.Name[0].ToString().ToUpper(), property.Name };
                    data.Add(item);
                }
            }

            var layout1 = BoxLayout2Samples.CreateTwoLevelLayout(data);


            layout1.PerformLayout();

            // Create a blank canvas in Visio
            var app       = SampleEnvironment.Application;
            var documents = app.Documents;
            var doc       = documents.Add(string.Empty);
            var page      = app.ActivePage;


            var domshapescol = new ShapeList();

            //var rect_master = dom.m
            foreach (var item in layout1.Nodes)
            {
                if (item.Data == null)
                {
                    continue;
                }
                var info = (TwoLevelInfo)item.Data;

                if (!info.Render)
                {
                    continue;
                }

                var shape = domshapescol.Drop("Rectangle", "Basic_U.VSS", item.Rectangle);

                if (info.Text != null)
                {
                    shape.Text = new VisioAutomation.Models.Text.Element(info.Text);
                }

                shape.Cells = info.ShapeCells.ShallowCopy();
            }
            domshapescol.Render(page);

            var bordersize = new VA.Geometry.Size(0.5, 0.5);

            page.ResizeToFitContents(bordersize);
        }
コード例 #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.Geometry.Size(5, 5);

            SampleEnvironment.SetPageSize(page, page_size);

            var lowerleft        = new VA.Geometry.Point(0, 0);
            var actual_page_size = SampleEnvironment.GetPageSize(page);
            var page_rect        = new VA.Geometry.Rectangle(lowerleft, actual_page_size);

            var layout = new GridLayout(num_cols, num_rows, new VA.Geometry.Size(1, 1), master);

            layout.RowDirection = RowDirection.TopToBottom;
            layout.Origin       = page_rect.UpperLeft;
            layout.CellSpacing  = new VA.Geometry.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.Models.Color.ColorRgb(0xffdddd);
            var color2 = new VA.Models.Color.ColorRgb(0x00ffff);

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

            var writer = new SidSrcWriter();

            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.FillForeground = color1_formula;
                format.FillBackground = color2_formula;
                format.LinePattern    = 0;
                format.LineWeight     = 0;

                writer.SetValues(shapeid, format);

                n++;
            }

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

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

            page.ResizeToFitContents(bordersize);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        public IVisio.Document DrawNamespaces(IList <Type> types)
        {
            this._client.Application.AssertApplicationAvailable();

            string template      = null;
            string def_linecolor = "rgb(140,140,140)";
            string def_fillcolor = "rgb(240,240,240)";
            string def_font      = "Segoe UI";

            var page_size = new VisioAutomation.Geometry.Size(8.5, 11);
            var doc       = this._client.Document.New(page_size, template);
            var fonts     = doc.Fonts;
            var font      = fonts[def_font];
            int fontid    = font.ID16;

            var pathbuilder = new PathTreeBuilder();

            foreach (var type in types)
            {
                pathbuilder.Add(type.Namespace);
            }

            var namespaces = pathbuilder.GetPaths();

            var tree_layout = new VisioAutomation.Models.Layouts.Tree.Drawing();

            tree_layout.LayoutOptions.Direction     = LayoutDirection.Right;
            tree_layout.LayoutOptions.ConnectorType = ConnectorType.CurvedBezier;
            var ns_node_map = new Dictionary <string, Node>(namespaces.Count);

            // create nodes for every namespace
            foreach (string ns in namespaces)
            {
                string label             = ns;
                int    index_of_last_sep = ns.LastIndexOf(pathbuilder.Separator, StringComparison.Ordinal);
                if (index_of_last_sep > 0)
                {
                    label = ns.Substring(index_of_last_sep + 1);
                }

                var node = new Node(ns);
                node.Text       = new VisioAutomation.Models.Text.Element(label);
                node.Size       = new VisioAutomation.Geometry.Size(2.0, 0.25);
                ns_node_map[ns] = node;
            }

            // add children to nodes
            foreach (string ns in namespaces)
            {
                var parent_ns = pathbuilder.PathToParentPath[ns];

                if (parent_ns != null)
                {
                    // the current namespace has a parent
                    var parent_node = ns_node_map[parent_ns];
                    var child_node  = ns_node_map[ns];
                    parent_node.Children.Add(child_node);
                }
                else
                {
                    // that means this namespace is a root, forget about it
                }
            }

            if (pathbuilder.Roots.Count == 0)
            {
            }
            else if (pathbuilder.Roots.Count == 1)
            {
                // when there is exactly one root namespace, then that node will be the tree's root node
                var first_root = pathbuilder.Roots[0];
                var root_n     = ns_node_map[first_root];
                tree_layout.Root = root_n;
            }
            else
            {
                // if there are multiple root namespaces, inject an empty placeholder root
                var root_n = new Node();
                tree_layout.Root = root_n;

                foreach (var root_ns in pathbuilder.Roots)
                {
                    var node = ns_node_map[root_ns];
                    tree_layout.Root.Children.Add(node);
                }
            }

            // format the shapes
            foreach (var node in tree_layout.Nodes)
            {
                if (node.Cells == null)
                {
                    node.Cells = new ShapeCells();
                }
                node.Cells.FillForeground      = def_fillcolor;
                node.Cells.CharFont            = fontid;
                node.Cells.LineColor           = def_linecolor;
                node.Cells.ParaHorizontalAlign = "0";
            }

            var cxn_cells = new ShapeCells();

            cxn_cells.LineColor = def_linecolor;
            tree_layout.LayoutOptions.ConnectorCells = cxn_cells;


            tree_layout.Render(doc.Application.ActivePage);

            DeveloperCommands.hide_ui_stuff(doc);
            return(doc);
        }