Ejemplo n.º 1
0
        public static int Set(IVisio.Shape shape, short row, ControlCells ctrl)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }


            if (ctrl.XDynamics.Value == null)
            {
                ctrl.XDynamics = string.Format("Controls.Row_{0}", row + 1);
            }

            if (ctrl.YDynamics.Value == null)
            {
                ctrl.YDynamics = string.Format("Controls.Row_{0}.Y", row + 1);
            }

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

            ctrl.SetFormulas(writer, row);

            writer.Commit(shape);

            return(row);
        }
        public short Render(IVisio.Shape shape)
        {
            short sec_index = ShapeGeometryHelper.AddSection(shape);
            short row_count = shape.RowCount[sec_index];

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

            var src_nofill      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoFill.Cell);
            var src_noline      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoLine.Cell);
            var src_noshow      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoShow.Cell);
            var src_nosnap      = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoSnap.Cell);
            var src_noquickdrag = new VA.ShapeSheet.Src(sec_index, 0, ShapeSheet.SrcConstants.GeometryNoQuickDrag.Cell);

            writer.SetValue(src_nofill, this.NoFill);
            writer.SetValue(src_noline, this.NoLine);
            writer.SetValue(src_noshow, this.NoShow);
            writer.SetValue(src_nosnap, this.NoSnap);
            writer.SetValue(src_noquickdrag, this.NoQuickDrag);

            foreach (var row in this.Rows)
            {
                row.AddTo(shape, writer, row_count, sec_index);
                row_count++;
            }

            writer.Commit(shape, CellValueType.Formula);

            return(0);
        }
Ejemplo n.º 3
0
        public void Page_Query()
        {
            var size           = new VA.Geometry.Size(4, 3);
            var page1          = this.GetNewPage(size);
            var page_fmt_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet, CellValueType.Formula);

            Assert.AreEqual("4 in", page_fmt_cells.Width.Value);
            Assert.AreEqual("3 in", page_fmt_cells.Height.Value);

            // Double each side
            var page_fmt_cells1 = page_fmt_cells;

            page_fmt_cells1.Width  = "8";
            page_fmt_cells1.Height = "6";

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

            page_fmt_cells1.SetFormulas(writer);

            writer.Commit(page1.PageSheet);

            var actual_page_format_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet, CellValueType.Result);

            Assert.AreEqual("8.0000 in.", actual_page_format_cells.Width.Value);
            Assert.AreEqual("6.0000 in.", actual_page_format_cells.Height.Value);
            page1.Delete(0);
        }
Ejemplo n.º 4
0
        public static int Add(
            IVisio.Shape shape,
            ConnectionPointCells connection_point_cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (connection_point_cells.X.Value == null)
            {
                string msg = "Must provide an X Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

            if (connection_point_cells.Y.Value == null)
            {
                string msg = "Must provide an Y Formula";
                throw new System.ArgumentException(msg, nameof(connection_point_cells));
            }

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

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

            writer.SetValues(connection_point_cells, n);

            writer.Commit(shape, VASS.CellValueType.Formula);

            return(n);
        }
Ejemplo n.º 5
0
        protected override void ProcessRecord()
        {
            if (this.FitContents)
            {
                var bordersize = new VisioAutomation.Geometry.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 old_page_format_cells = VisioAutomation.Pages.PageFormatCells.GetCells(page.PageSheet, CellValueType.Formula);

                var new_page_format_cells = new VisioAutomation.Pages.PageFormatCells();

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

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

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                new_page_format_cells.SetFormulas(writer);
                writer.BlastGuards = true;

                writer.Commit(page);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Remove all tab stops on the shape
        /// </summary>
        /// <param name="shape"></param>
        private static void _clear_tab_stops(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            int num_existing_tabstops = _get_tab_stop_count(shape);

            if (num_existing_tabstops < 1)
            {
                return;
            }

            var cell_tabstopcount = shape.CellsSRC[ShapeSheet.SrcConstants.TabStopCount.Section, ShapeSheet.SrcConstants.TabStopCount.Row, ShapeSheet.SrcConstants.TabStopCount.Cell];

            cell_tabstopcount.FormulaForce = "0";

            const string formula = "0";

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

            for (int i = 1; i < num_existing_tabstops * 3; i++)
            {
                var src = new ShapeSheet.Src(tab_section, (short)IVisio.VisRowIndices.visRowTab,
                                             (short)i);
                writer.SetValue(src, formula);
            }

            writer.Commit(shape, VASS.CellValueType.Formula);
        }
Ejemplo n.º 7
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);
                }
            }
        }
        public void ShapeSheet_Writer_ResultsString_SingleShape()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var writer = new VASS.Writers.SrcWriter();

            writer.SetValue(LinePattern, "7");
            writer.Commit(shape1, VASS.CellValueType.Formula);

            // Build the query
            var query       = new VASS.Query.CellQuery();
            var col_linepat = query.Columns.Add(LinePattern, nameof(LinePattern));

            // Retrieve the values
            var data_formulas = query.GetFormulas(shape1);
            var data_results  = query.GetResults <double>(shape1);

            int rownum = 0;

            // Verify
            Assert.AreEqual("7", data_formulas[rownum][col_linepat]);
            Assert.AreEqual(7, data_results[rownum][col_linepat]);
            page1.Delete(0);
        }
Ejemplo n.º 9
0
        public void Page_Query()
        {
            var size           = new VA.Drawing.Size(4, 3);
            var page1          = this.GetNewPage(size);
            var page_fmt_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet);

            Assert.AreEqual("4.0000 in.", page_fmt_cells.Width.Result);
            Assert.AreEqual("3.0000 in.", page_fmt_cells.Height.Result);

            // Double each side
            page_fmt_cells.Width  = "8.0";
            page_fmt_cells.Height = "6.0";

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

            page_fmt_cells.SetFormulas(writer);

            writer.Commit(page1.PageSheet);

            var actual_page_format_cells = VA.Pages.PageFormatCells.GetCells(page1.PageSheet);

            Assert.AreEqual("8.0000 in.", actual_page_format_cells.Width.Result);
            Assert.AreEqual("6.0000 in.", actual_page_format_cells.Height.Result);
            page1.Delete(0);
        }
Ejemplo n.º 10
0
        private static void VerifyPageSizeToFit(IVisio.Document doc,
                                                VA.Geometry.Size bottomleft_margin,
                                                VA.Geometry.Size upperright_margin,
                                                VA.Geometry.Size shape_size,
                                                VA.Geometry.Size padding_size,
                                                double expected_pinx,
                                                double expected_piny)
        {
            var page = doc.Pages.Add();

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

            pagecells.TopMargin    = upperright_margin.Height;
            pagecells.BottomMargin = bottomleft_margin.Height;
            pagecells.LeftMargin   = bottomleft_margin.Width;
            pagecells.RightMargin  = upperright_margin.Width;

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

            pagecells.SetFormulas(page_writer);

            page_writer.Commit(page.PageSheet);


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

            page.ResizeToFitContents(padding_size);
            var xform  = VA.Shapes.ShapeXFormCells.GetCells(shape, CellValueType.Result);
            var pinpos = xform.GetPinPosResult();

            Assert.AreEqual(expected_pinx, pinpos.X, 0.1);
            Assert.AreEqual(expected_piny, pinpos.Y, 0.1);
            page.Delete(0);
        }
Ejemplo n.º 11
0
        internal static void SetSize(IVisio.Page page, Geometry.Size size)
        {
            var writer = new VASS.Writers.SrcWriter();

            writer.SetValue(VASS.SrcConstants.PageWidth, size.Width);
            writer.SetValue(VASS.SrcConstants.PageHeight, size.Height);

            writer.Commit(page.PageSheet, VASS.CellValueType.Formula);
        }
Ejemplo n.º 12
0
        internal static void SetSize(IVisio.Page page, Drawing.Size size)
        {
            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, size.Width);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, size.Height);

            writer.Commit(page.PageSheet);
        }
Ejemplo n.º 13
0
        public static void Set(IVisio.Shape shape, string name, UserDefinedCellCells cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (cells == null)
            {
                throw new System.ArgumentNullException(nameof(cells));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                // The user-defined cell already exists
                string full_udcell_name = UserDefinedCellHelper.__GetRowName(name);

                if (cells.Value.HasValue)
                {
                    string value_cell_name = full_udcell_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = cells.Value.Value;
                }

                if (cells.Prompt.HasValue)
                {
                    string prompt_cell_name = full_udcell_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = cells.Prompt.Value;
                }
            }
            else
            {
                // The user-defined cell doesn't already exist
                short row        = shape.AddNamedRow(_udcell_section, name, (short)IVisio.VisRowIndices.visRowUser);
                var   src_value  = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                var   src_prompt = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);

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

                if (cells.Value.HasValue)
                {
                    writer.SetValue(src_value, cells.Value.Value);
                }

                if (cells.Prompt.HasValue)
                {
                    writer.SetValue(src_prompt, cells.Prompt.Value);
                }

                writer.Commit(shape, VASS.CellValueType.Formula);
            }
        }
        public void ShapeSheet_Writer_Write_nothing()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var writer = new VASS.Writers.SrcWriter();

            writer.Commit(shape1, VASS.CellValueType.Formula);

            page1.Delete(0);
        }
Ejemplo n.º 15
0
        public static void Set(IVisio.Shape shape, string name, ShapeSheet.CellValueLiteral udfcell_value, ShapeSheet.CellValueLiteral udfcell_prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellHelper.GetRowName(name);

                if (udfcell_value.HasValue)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_value.Value);
                }

                if (udfcell_prompt.HasValue)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_prompt.Value);
                }
                return;
            }

            short row = shape.AddNamedRow(
                UserDefinedCellHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

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

            if (udfcell_value.HasValue)
            {
                var src     = new ShapeSheet.Src(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                var formula = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_value.Value);
                writer.SetFormula(src, formula);
            }

            if (udfcell_prompt.HasValue)
            {
                var src     = new ShapeSheet.Src(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                var formula = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_prompt.Value);
                writer.SetFormula(src, formula);
            }

            writer.Commit(shape);
        }
Ejemplo n.º 16
0
        public static void Set(IVisio.Shape shape, short row, CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

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

            cp.SetFormulas(writer, row);

            writer.Commit(shape);
        }
Ejemplo n.º 17
0
        public void Apply(IVisio.Page page)
        {
            var page_layout_cells = new VisioAutomation.Pages.PageLayoutCells();

            this._set_page_cells(page_layout_cells);

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

            writer.SetValues(page_layout_cells);

            writer.Commit(page.PageSheet, CellValueType.Formula);
            page.Layout();
        }
Ejemplo n.º 18
0
        public void Apply(IVisio.Page page)
        {
            var page_layout_cells = new VisioAutomation.Pages.PageLayoutCells();

            this.SetPageCells(page_layout_cells);

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

            page_layout_cells.SetFormulas(writer);

            writer.Commit(page.PageSheet);
            page.Layout();
        }
Ejemplo n.º 19
0
        public static void SetTabStops(IVisio.Shape shape, IList <TabStop> stops)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (stops == null)
            {
                throw new System.ArgumentNullException(nameof(stops));
            }

            _clear_tab_stops(shape);
            if (stops.Count < 1)
            {
                return;
            }

            const short row                = 0;
            var         culture            = System.Globalization.CultureInfo.InvariantCulture;
            var         vis_tab_stop_count = (short)IVisio.VisCellIndices.visTabStopCount;
            var         tabstopcountcell   = shape.CellsSRC[tab_section, row, vis_tab_stop_count];

            tabstopcountcell.FormulaU = stops.Count.ToString(culture);

            // set the number of tab stobs allowed for the shape
            var tagtab = _get_tab_tag_for_stops(stops.Count);

            shape.RowType[tab_section, (short)IVisio.VisRowIndices.visRowTab] = (short)tagtab;

            // add tab properties for each stop
            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            for (int stop_index = 0; stop_index < stops.Count; stop_index++)
            {
                int i = stop_index * 3;

                var alignment = ((int)stops[stop_index].Alignment).ToString(culture);
                var position  = ((int)stops[stop_index].Position).ToString(culture);

                var src_tabpos   = new ShapeSheet.Src(tab_section, row, (short)(i + 1));
                var src_tabalign = new ShapeSheet.Src(tab_section, row, (short)(i + 2));
                var src_tabother = new ShapeSheet.Src(tab_section, row, (short)(i + 3));

                writer.SetValue(src_tabpos, position);    // tab position
                writer.SetValue(src_tabalign, alignment); // tab alignment
                writer.SetValue(src_tabother, "0");       // tab unknown
            }

            writer.Commit(shape, VASS.CellValueType.Formula);
        }
Ejemplo n.º 20
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);
                }
            }
        }
Ejemplo n.º 21
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);
                }
            }
        }
Ejemplo n.º 22
0
        public static void SetPageSize(IVisio.Page page, VisioAutomation.Geometry.Size size)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var page_sheet = page.PageSheet;

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

            writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, size.Width);
            writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, size.Height);

            writer.Commit(page_sheet, CellValueType.Formula);
        }
Ejemplo n.º 23
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageLayoutFormulas();

            this.SetPageCells(pagecells);

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

            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutAvenueSizeX, pagecells.AvenueSizeX);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutAvenueSizeY, pagecells.AvenueSizeY);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutLineRouteExt, pagecells.LineRouteExt);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutRouteStyle, pagecells.RouteStyle);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutPlaceStyle, pagecells.PlaceStyle);

            writer.Commit(page.PageSheet);
            page.Layout();
        }
Ejemplo n.º 24
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            ConnectionPointCells cpcells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

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

            writer.SetValues(cpcells, row);

            writer.Commit(shape, VASS.CellValueType.Formula);

            return(row);
        }
Ejemplo n.º 25
0
        public void SetSize(VisioAutomation.Drawing.Size new_size)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            using (var undoscope = this._client.Application.NewUndoScope("Set Page Size"))
            {
                var active_page = application.ActivePage;
                var page_sheet  = active_page.PageSheet;
                var writer      = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_size.Width);
                writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_size.Height);

                writer.Commit(page_sheet);
            }
        }
Ejemplo n.º 26
0
        public static int Set(
            IVisio.Shape shape,
            short row,
            HyperlinkCells hyperlink)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

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

            hyperlink.SetFormulas(writer, row);

            writer.Commit(shape);

            return(row);
        }
        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);
        }
Ejemplo n.º 28
0
        public void SetOrientation(VisioScripting.Models.PageOrientation orientation)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            var app         = this._client.Application.Get();
            var application = app;

            var active_page = application.ActivePage;

            if (orientation != VisioScripting.Models.PageOrientation.Landscape && orientation != VisioScripting.Models.PageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            var old_orientation = PageCommands.GetOrientation(active_page);

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

            var old_size = this.GetSize();

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

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

            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_width);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_height);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PrintPageOrientation, (int)orientation);

            using (var undoscope = this._client.Application.NewUndoScope("Set Page Orientation"))
            {
                writer.Commit(active_page.PageSheet);
            }
        }
Ejemplo n.º 29
0
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.CheckValidCustomPropertyName(name);

            if (CustomPropertyHelper.Contains(shape, name))
            {
                string full_prop_name = CustomPropertyHelper.GetRowName(name);
                var    cell_propname  = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = string.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new InternalAssertionException(msg);
                }

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                cp.SetFormulas(writer, cell_propname.Row);

                writer.Commit(shape);

                return;
            }

            short row = shape.AddNamedRow(
                (short)IVisio.VisSectionIndices.visSectionProp,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            CustomPropertyHelper.Set(shape, row, cp);
        }
Ejemplo n.º 30
0
        public void ResetOrigin(IVisio.Page page)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            if (page == null)
            {
                page = application.ActivePage;
            }

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

            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.XGridOrigin, "0.0");
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.YGridOrigin, "0.0");
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.XRulerOrigin, "0.0");
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.YRulerOrigin, "0.0");

            using (var undoscope = this._client.Application.NewUndoScope("Reset Page Origin"))
            {
                writer.Commit(page.PageSheet);
            }
        }