Esempio n. 1
0
        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.ResolveToPages(this._client);

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

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

                    var old_size = VisioAutomation.Pages.PageHelper.GetSize(page);

                    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, CellValueType.Formula);
                }
            }
        }
Esempio n. 2
0
        public void DeletePages(TargetPages targetpages, bool renumber)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            foreach (var page in targetpages.Pages)
            {
                page.Delete(renumber ? (short)1 : (short)0);
            }
        }
Esempio n. 3
0
        public void LayoutPage(TargetPages targetpages, VisioAutomation.Models.LayoutStyles.LayoutStyleBase layout)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageSize)))
            {
                foreach (var page in targetpages.Pages)
                {
                    layout.Apply(page);
                }
            }
        }
Esempio n. 4
0
        public void ResizePageToFitContents(TargetPages targetpages, VisioAutomation.Geometry.Size bordersize)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(ResizePageToFitContents)))
            {
                foreach (var page in targetpages.Pages)
                {
                    page.ResizeToFitContents(bordersize);
                }
            }
        }
Esempio n. 5
0
        public void SetPageBackground(TargetPages targetpages, string background_page_name)
        {
            if (background_page_name == null)
            {
                throw new System.ArgumentNullException(nameof(background_page_name));
            }

            targetpages = targetpages.ResolveToPages(this._client);

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

            var page0     = targetpages.Pages[0];
            var doc       = page0.Document;
            var doc_pages = doc.Pages;

            var names = new HashSet <string>(doc_pages.GetNamesU());

            if (!names.Contains(background_page_name))
            {
                string msg = string.Format("Could not find page with name \"{0}\"", background_page_name);
                throw new VisioAutomation.Exceptions.VisioOperationException(msg);
            }

            var bgpage = doc_pages.ItemU[background_page_name];

            // Set the background page
            // Check that the intended background is indeed a background page
            if (bgpage.Background == 0)
            {
                string msg = string.Format("Page \"{0}\" is not a background page", bgpage.Name);
                throw new VisioAutomation.Exceptions.VisioOperationException(msg);
            }

            // don't allow the page to be set as a background to itself

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageBackground)))
            {
                foreach (var page in targetpages.Pages)
                {
                    if (page == bgpage)
                    {
                        string msg = "Cannot set page as its own background page";
                        throw new VisioAutomation.Exceptions.VisioOperationException(msg);
                    }

                    page.BackPage = bgpage;
                }
            }
        }
Esempio n. 6
0
        public void SetPageFormatCells(TargetPages targetpages, VisioAutomation.Pages.PageFormatCells cells)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageFormatCells)))
            {
                foreach (var page in targetpages.Pages)
                {
                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValues(cells);
                    writer.BlastGuards = true;
                    writer.Commit(page, CellValueType.Formula);
                }
            }
        }
Esempio n. 7
0
        public void SetPageSize(TargetPages targetpages, VisioAutomation.Geometry.Size new_size)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageSize)))
            {
                foreach (var page in targetpages.Pages)
                {
                    var page_sheet = page.PageSheet;
                    var writer     = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_size.Width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_size.Height);
                    writer.Commit(page_sheet, CellValueType.Formula);
                }
            }
        }
Esempio n. 8
0
        public List <VisioAutomation.Geometry.Size> GetPageSize(TargetPages targetpages)
        {
            targetpages = targetpages.ResolveToPages(this._client);

            if (targetpages.Pages.Count < 1)
            {
                return(new List <VisioAutomation.Geometry.Size>(0));
            }

            var sizes = new List <VisioAutomation.Geometry.Size>(targetpages.Pages.Count);

            foreach (var page in targetpages.Pages)
            {
                var size = VisioAutomation.Pages.PageHelper.GetSize(page);
                sizes.Add(size);
            }

            return(sizes);
        }