コード例 #1
0
        protected override void ProcessRecord()
        {
            var target_pages = new VisioScripting.Models.TargetPages(this.Pages);

            target_pages.Resolve(this.Client);
            this.Client.Page.DeletePages(target_pages, this.Renumber);
        }
コード例 #2
0
        public void Page_Orientation()
        {
            var size = new VA.Geometry.Size(4, 3);

            var page1    = this.GetNewPage(size);
            var page1_tp = new VisioScripting.Models.TargetPages(page1);

            var client = this.GetScriptingClient();

            var orientation_1 = client.Page.GetPageOrientation(page1_tp);

            Assert.AreEqual(VisioScripting.Models.PageOrientation.Portrait, orientation_1);

            var size1 = client.Page.GetPageSize(page1_tp);

            Assert.AreEqual(size, size1);

            client.Page.SetPageOrientation(page1_tp, VisioScripting.Models.PageOrientation.Landscape);

            client.Page.SetPageOrientation(page1_tp, VisioScripting.Models.PageOrientation.Landscape);

            var orientation_2 = client.Page.GetPageOrientation(page1_tp);

            Assert.AreEqual(VisioScripting.Models.PageOrientation.Landscape, orientation_2);

            var actual_final_size   = client.Page.GetPageSize(page1_tp);
            var expected_final_size = new VA.Geometry.Size(3, 4);

            Assert.AreEqual(expected_final_size, actual_final_size);

            page1.Delete(0);
        }
コード例 #3
0
        protected override void ProcessRecord()
        {
            var target_pages = new VisioScripting.Models.TargetPages(this.Pages);

            var template  = new VisioPowerShell.Models.PageCells();
            var celldic   = VisioPowerShell.Models.NameCellDictionary.FromCells(template);
            var cellnames = celldic.Keys.ToArray();
            var query     = _CreateQuery(celldic, cellnames);
            var surface   = this.Client.ShapeSheet.GetShapeSheetSurface();

            var result_dt = new System.Data.DataTable();

            foreach (var target_page in target_pages.Pages)
            {
                var target_pagesheet = target_page.PageSheet;
                var target_shapeids  = new List <int> {
                    target_pagesheet.ID
                };
                var dt = VisioPowerShell.Models.DataTableHelpers.QueryToDataTable(query, this.OutputType, target_shapeids, surface);
                result_dt.Merge(dt);
            }

            // Annotate the returned datatable to disambiguate rows
            var pageindex_col = result_dt.Columns.Add("PageIndex", typeof(System.Int32));

            pageindex_col.SetOrdinal(0);
            for (int row_index = 0; row_index < target_pages.Pages.Count; row_index++)
            {
                result_dt.Rows[row_index][pageindex_col.ColumnName] = target_pages.Pages[row_index].Index;
            }

            this.WriteObject(result_dt);
        }
コード例 #4
0
        protected override void ProcessRecord()
        {
            if (this.FitContents || this.Width > 0 || this.Height > 0)
            {
                var cmdtarget = this.Client.GetCommandTargetPage();
                var tp        = new VisioScripting.Models.TargetPages(cmdtarget.ActivePage);

                if (this.FitContents)
                {
                    var bordersize = new VisioAutomation.Geometry.Size(this.BorderWidth, this.BorderWidth);
                    this.Client.Page.ResizePageToFitContents(tp, bordersize);
                    this.Client.View.SetActiveWindowZoomToObject(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(tp, page_format_cells);
                }
            }


            if (this.Orientation.HasValue)
            {
                var cmdtarget = this.Client.GetCommandTargetPage();
                var tp        = new VisioScripting.Models.TargetPages(cmdtarget.ActivePage);
                this.Client.Page.SetPageOrientation(tp, this.Orientation.Value);
            }

            if (this.BackgroundPage != null)
            {
                this.Client.Page.SetActivePageBackground(this.BackgroundPage);
            }

            if (this.LayoutStyle != null)
            {
                var cmdtarget = this.Client.GetCommandTargetPage();
                var tp        = new VisioScripting.Models.TargetPage(cmdtarget.ActivePage);
                this.Client.Page.LayoutPage(tp, this.LayoutStyle);
            }
        }
コード例 #5
0
        public void SetPageSize(Models.TargetPage target_page, double?width, double?height)
        {
            if (!width.HasValue && !height.HasValue)
            {
                // nothing to do
                return;
            }

            var page     = this._client.Page.GetActivePage();
            var tp       = new VisioScripting.Models.TargetPages(page);
            var old_size = this.GetPageSize(tp);
            var w        = width.GetValueOrDefault(old_size.Width);
            var h        = height.GetValueOrDefault(old_size.Height);
            var new_size = new VisioAutomation.Geometry.Size(w, h);

            this.SetPageSize(new Models.TargetPages(target_page.Page), new_size);
        }
コード例 #6
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);
        }
コード例 #7
0
        public void NewDirectedGraphDocument(IList <GRAPH.DirectedGraphLayout> graph)
        {
            var cmdtarget = this._client.GetCommandTargetApplication();

            this._client.Output.WriteVerbose("Start rendering directed graph");
            var app = cmdtarget.Application;

            this._client.Output.WriteVerbose("Creating a New Document For the Directed Graphs");
            string template = null;
            var    doc      = this._client.Document.NewDocumentFromTemplate(template);

            int num_pages_created = 0;
            var doc_pages         = doc.Pages;

            foreach (int i in Enumerable.Range(0, graph.Count))
            {
                var dg = graph[i];


                var options = new GRAPH.MsaglLayoutOptions();
                options.UseDynamicConnectors = false;

                // if this is the first page to drawe
                // then reuse the initial empty page in the document
                // otherwise, create a new page.
                var page = num_pages_created == 0 ? app.ActivePage : doc_pages.Add();

                this._client.Output.WriteVerbose("Rendering page: {0}", i + 1);
                dg.Render(page, options);

                var tp = new VisioScripting.Models.TargetPages(page);
                this._client.Page.ResizePageToFitContents(tp, new VisioAutomation.Geometry.Size(1.0, 1.0));
                this._client.View.SetActiveWindowZoomToObject(VisioScripting.Models.ZoomToObject.Page);
                this._client.Output.WriteVerbose("Finished rendering page");

                num_pages_created++;
            }

            this._client.Output.WriteVerbose("Finished rendering all pages");
            this._client.Output.WriteVerbose("Finished rendering directed graph.");
        }
コード例 #8
0
        protected override void ProcessRecord()
        {
            if (this.Cells == null)
            {
                return;
            }

            if (this.Cells.Length < 1)
            {
                return;
            }

            var target_pages = new VisioScripting.Models.TargetPages(this.Pages);

            this.Client.Output.WriteVerbose("BlastGuards: {0}", this.BlastGuards);
            this.Client.Output.WriteVerbose("TestCircular: {0}", this.TestCircular);

            using (var undoscope = this.Client.Undo.NewUndoScope(nameof(SetVisioPageCells)))
            {
                for (int i = 0; i < target_pages.Pages.Count; i++)
                {
                    var target_page = target_pages.Pages[i];
                    this.Client.Output.WriteVerbose("Start Update Page Name={0}", target_page.NameU);

                    var target_pagesheet    = target_page.PageSheet;
                    int target_pagesheet_id = target_pagesheet.ID;
                    var target_cells        = this.Cells[i % this.Cells.Length];
                    var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter();
                    writer.BlastGuards  = this.BlastGuards;
                    writer.TestCircular = this.TestCircular;
                    target_cells.Apply(writer, (short)target_pagesheet_id);
                    writer.CommitFormulas(target_page);

                    this.Client.Output.WriteVerbose("End Update Page Name={0}", target_page.NameU);
                }
            }
        }
コード例 #9
0
        public void SetPageOrientation(Models.TargetPages target_pages, Models.PageOrientation orientation)
        {
            if (orientation != VisioScripting.Models.PageOrientation.Landscape && orientation != VisioScripting.Models.PageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            var pages = target_pages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageOrientation)))
            {
                foreach (var page in pages)
                {
                    var old_orientation = PageCommands._GetPageOrientation(page);

                    if (old_orientation == orientation)
                    {
                        // don't need to do anything
                        return;
                    }

                    var page_tp  = new VisioScripting.Models.TargetPages(page);
                    var old_size = this.GetPageSize(page_tp);

                    double new_height = old_size.Width;
                    double new_width  = old_size.Height;

                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_height);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PrintPageOrientation, (int)orientation);

                    writer.CommitFormulas(page.PageSheet);
                }
            }
        }
コード例 #10
0
        public List <IVisio.Shape> NewDataTablePageInActiveDocument(
            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");
            }

            var    cmdtarget          = this._client.GetCommandTargetPage();
            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];

            var active_document = cmdtarget.ActiveDocument;
            var pages           = active_document.Pages;

            var page = pages.Add();

            page.Background = 0; // ensure this is a foreground page

            var page_tp  = new VisioScripting.Models.TargetPages(page);
            var pagesize = this._client.Page.GetPageSize(page_tp);

            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(NewDataTablePageInActiveDocument)))
            {
                layout.Render(page);
                page.ResizeToFitContents();
            }

            var shapes = layout.Nodes.Select(n => n.Shape).ToList();

            return(shapes);
        }