public void SetPageOrientation(TargetPages targetpages, 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");
            }

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

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

                    var page_tp  = new VisioScripting.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.Commit(page.PageSheet, VASS.CellValueType.Formula);
                }
            }
        }
        public void Page_Orientation()
        {
            var size = new VA.Geometry.Size(4, 3);

            var page1    = this.GetNewPage(size);
            var page1_tp = new VisioScripting.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);
        }
Example #3
0
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Pages);

            var template  = new VisioPowerShell.Models.PageCells();
            var celldic   = VisioPowerShell.Models.NamedSrcDictionary.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 targetpage in targetpages.Pages)
            {
                var targetpage_shapesheet    = targetpage.PageSheet;
                var targetpage_shapeshapeids = new List <int> {
                    targetpage_shapesheet.ID
                };
                var dt = VisioPowerShell.Models.DataTableHelpers.QueryToDataTable(query, this.OutputType, targetpage_shapeshapeids, 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 < targetpages.Pages.Count; row_index++)
            {
                result_dt.Rows[row_index][pageindex_col.ColumnName] = targetpages.Pages[row_index].Index;
            }

            this.WriteObject(result_dt);
        }
Example #4
0
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Page).ResolveToPages(this.Client);

            if (targetpages.Pages.Count < 1)
            {
                return;
            }

            var list_pagedim = VisioScripting.Models.PageDimensions.Get_PageDimensions(targetpages.Pages);

            this.WriteObject(list_pagedim, true);
        }
Example #5
0
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages().Resolve(this.Client);

            if (this.FitContents || this.Width > 0 || this.Height > 0)
            {
                if (this.FitContents)
                {
                    var bordersize = new VisioAutomation.Geometry.Size(this.BorderWidth, this.BorderWidth);
                    this.Client.Page.ResizeToFitContents(targetpages, 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(targetpages, page_format_cells);
                }
            }


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

            if (this.BackgroundPage != null)
            {
                // TODO: SetActivePageBackground should handle targetpages
                this.Client.Page.SetBackground(targetpages, this.BackgroundPage);
            }

            if (this.LayoutStyle != null)
            {
                this.Client.Page.LayoutPage(targetpages, this.LayoutStyle);
            }
        }
        public void SetPageSize(TargetPage targetpage, double?width, double?height)
        {
            if (!width.HasValue && !height.HasValue)
            {
                // nothing to do
                return;
            }

            var page        = this._client.Page.GetActivePage();
            var targetpages = new VisioScripting.TargetPages(page);
            var old_size    = this.GetPageSize(targetpages);
            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 TargetPages(targetpage.Page), new_size);
        }
        protected override void ProcessRecord()
        {
            var valuetype = this.Results
                ? VisioAutomation.ShapeSheet.CellValueType.Result
                : VisioAutomation.ShapeSheet.CellValueType.Formula;

            var targetpages = new VisioScripting.TargetPages(this.Page).ResolveToPages(this.Client);

            if (targetpages.Pages.Count < 1)
            {
                return;
            }

            var template           = new VisioPowerShell.Models.PageCells();
            var dicof_name_to_cell = VisioPowerShell.Internal.NamedSrcDictionary.FromCells(template);
            var desired_cells      = this.Cell ?? dicof_name_to_cell.Keys.ToArray();
            var query = _create_query(dicof_name_to_cell, desired_cells);

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

            foreach (var page in targetpages.Pages)
            {
                var shapesheet = page.PageSheet;
                var shapeids   = new List <int> {
                    shapesheet.ID
                };
                var surface        = new VisioAutomation.SurfaceTarget(page);
                var temp_datatable = VisioPowerShell.Internal.DataTableHelpers.QueryToDataTable(query, valuetype, this.ResultType, shapeids, surface);
                datatable.Merge(temp_datatable);
            }

            // Annotate the returned datatable to disambiguate rows
            var pageid_col      = datatable.Columns.Add("PageID", typeof(int));
            int pageid_colindex = 0;

            pageid_col.SetOrdinal(pageid_colindex);
            foreach (int row_index in Enumerable.Range(0, targetpages.Pages.Count))
            {
                var page = targetpages.Pages[row_index];
                datatable.Rows[row_index][pageid_colindex] = page.ID;
            }

            this.WriteObject(datatable);
        }
Example #8
0
        public void DrawDirectedGraphDocument(GRAPH.DirectedGraphDocument dgdoc, GRAPH.DirectedGraphStyling dgstyling)
        {
            var cmdtarget = this._client.GetCommandTarget(CommandTargetFlags.RequireApplication);

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

            this._client.Output.WriteVerbose("Creating a New Document For the Directed Graphs");
            this._client.Output.WriteVerbose("Number of Layouts: {0}", dgdoc.Layouts.Count);
            this._client.Output.WriteVerbose("Template: {0}", dgdoc.Template);
            var doc = this._client.Document.NewDocumentFromTemplate(dgdoc.Template);

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

            foreach (int i in Enumerable.Range(0, dgdoc.Layouts.Count))
            {
                var dg_layout = dgdoc.Layouts[i];

                // if this is the first page to draw
                // 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 on page: \"{0}\",{1}", page.Name, i + 1);

                var renderer = new GRAPH.MsaglRenderer();
                renderer.LayoutOptions.UseDynamicConnectors = false;
                renderer.Render(page, dg_layout);

                var targetpages = new VisioScripting.TargetPages(page);

                this._client.Page.ResizePageToFitContents(targetpages, dgdoc.BorderSize);
                this._client.View.SetZoomToObject(VisioScripting.TargetWindow.Auto, 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.");
        }
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Page).ResolveToPages(this.Client);

            if (targetpages.Pages.Count < 1)
            {
                return;
            }

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

            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)))
            {
                foreach (int i in Enumerable.Range(0, targetpages.Pages.Count))
                {
                    int page_index  = i;
                    int cells_index = i % this.Cells.Length;

                    var page  = targetpages.Pages[page_index];
                    var cells = this.Cells[cells_index];

                    this.Client.Output.WriteVerbose("Start Update Page Name={0}", page.NameU);

                    var shapesheet = page.PageSheet;
                    int shapeid    = shapesheet.ID;

                    var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter();
                    writer.BlastGuards  = this.BlastGuards;
                    writer.TestCircular = this.TestCircular;
                    cells.Apply(writer, (short)shapeid);
                    writer.Commit(page, VisioAutomation.ShapeSheet.CellValueType.Formula);

                    this.Client.Output.WriteVerbose("End Update Page Name={0}", page.NameU);
                }
            }
        }
Example #10
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 targetpages = new VisioScripting.TargetPages(page);
                this._client.Page.ResizeToFitContents(targetpages, 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.");
        }
        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 tagetpages = new VisioScripting.TargetPages(page);

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

            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);

            var targetdoc = new VisioScripting.TargetDocument();

            client.Document.CloseDocument(targetdoc, true);
        }
Example #12
0
        protected override void ProcessRecord()
        {
            if (this.Cells == null)
            {
                return;
            }

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

            var targetpages = new VisioScripting.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 < targetpages.Pages.Count; i++)
                {
                    var targetpage = targetpages.Pages[i];
                    this.Client.Output.WriteVerbose("Start Update Page Name={0}", targetpage.NameU);

                    var targetpage_shapesheet   = targetpage.PageSheet;
                    int targetpage_shapesheetid = targetpage_shapesheet.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)targetpage_shapesheetid);
                    writer.Commit(targetpage, VisioAutomation.ShapeSheet.CellValueType.Formula);

                    this.Client.Output.WriteVerbose("End Update Page Name={0}", targetpage.NameU);
                }
            }
        }
Example #13
0
        protected override void ProcessRecord()
        {
            var targetpages = new VisioScripting.TargetPages(this.Page);

            this.Client.Page.DeletePages(targetpages, this.Renumber);
        }
Example #14
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 targetpages = new VisioScripting.TargetPages(page);
            var pagesize    = this._client.Page.GetPageSize(targetpages);

            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);
        }