public void Scripting_ConnectionPoints_Scenarios()
        {
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(new VisioAutomation.Geometry.Size(4, 4), false);

            var s1 = client.Draw.Rectangle(1, 1, 1.25, 1.5);
            var s2 = client.Draw.Rectangle(2, 3, 2.5, 3.5);
            var s3 = client.Draw.Rectangle(4.5, 2.5, 6, 3.5);

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

            var indices0 = client.ConnectionPoint.Add("0", "Width*0.67", VisioScripting.Models.ConnectionPointType.Outward);

            Assert.AreEqual(3, indices0.Count);
            Assert.AreEqual(0, indices0[0]);
            Assert.AreEqual(0, indices0[1]);
            Assert.AreEqual(0, indices0[2]);

            var targets = new VisioScripting.Models.TargetShapes();
            var dic     = client.ConnectionPoint.GetFormulas(targets);

            Assert.AreEqual(3, dic.Count);
            Assert.AreEqual("Width*0.67", dic[s1][0].Y.Value);
            Assert.AreEqual("Width*0.67", dic[s2][0].Y.Value);
            Assert.AreEqual("Width*0.67", dic[s2][0].Y.Value);

            client.ConnectionPoint.Delete(targets, 0);
            client.Document.Close(true);
        }
Beispiel #2
0
        public void SetSize(VisioScripting.Models.TargetShapes targets, double?w, double?h)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            targets = targets.ResolveShapes(this._client);
            if (targets.Shapes.Count < 1)
            {
                return;
            }

            var active_page = this._client.Page.Get();
            var shapeids    = targets.ToShapeIDs();
            var writer      = new SidSrcWriter();

            foreach (int shapeid in shapeids.ShapeIDs)
            {
                if (w.HasValue && w.Value >= 0)
                {
                    writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, w.Value);
                }
                if (h.HasValue && h.Value >= 0)
                {
                    writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, h.Value);
                }
            }

            using (var undoscope = this._client.Application.NewUndoScope("Set Shape Size"))
            {
                writer.Commit(active_page);
            }
        }
Beispiel #3
0
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);

            var lockcells = new VisioAutomation.Shapes.LockCells();


            lockcells.Aspect          = this.Aspect ? "1": null;
            lockcells.Begin           = this.Begin ? "1" : null;
            lockcells.CalcWH          = this.CalcWH ? "1" : null;
            lockcells.Crop            = this.Crop ? "1" : null;
            lockcells.CustProp        = this.CustProp ? "1" : null;
            lockcells.Delete          = this.Delete ? "1" : null;
            lockcells.End             = this.End ? "1" : null;
            lockcells.Format          = this.Format ? "1" : null;
            lockcells.FromGroupFormat = this.FromGroupFormat ? "1" : null;
            lockcells.Group           = this.Group ? "1" : null;
            lockcells.Height          = this.Height ? "1" : null;
            lockcells.MoveX           = this.MoveX ? "1" : null;
            lockcells.MoveY           = this.MoveY ? "1" : null;
            lockcells.Rotate          = this.Rotate ? "1" : null;
            lockcells.Select          = this.Select ? "1" : null;
            lockcells.TextEdit        = this.TextEdit ? "1" : null;
            lockcells.ThemeColors     = this.ThemeColors ? "1" : null;
            lockcells.ThemeEffects    = this.ThemeEffects ? "1" : null;
            lockcells.VertexEdit      = this.VertexEdit ? "1" : null;
            lockcells.Width           = this.Width ? "1" : null;

            this.Client.Lock.SetLockCells(targets, lockcells);
        }
Beispiel #4
0
        public void Set(VisioScripting.Models.TargetShapes targets, IList <string> texts)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            if (texts == null || texts.Count < 1)
            {
                return;
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Application.NewUndoScope("Set Shape Text"))
            {
                // Apply text to each shape
                // if there are fewer texts than shapes then
                // start reusing the texts from the beginning

                int count = 0;
                foreach (var shape in targets.Shapes)
                {
                    string text = texts[count % texts.Count];
                    if (text != null)
                    {
                        shape.Text = text;
                    }
                    count++;
                }
            }
        }
Beispiel #5
0
        public void Delete(VisioScripting.Models.TargetShapes targets, string name)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name cannot be empty", nameof(name));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Application.NewUndoScope("Delete Custom Property"))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Delete(shape, name);
                }
            }
        }
Beispiel #6
0
        public void Scripting_Grouping()
        {
            var client = this.GetScriptingClient();

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

            var shape_rect  = client.Draw.DrawRectangle(1, 1, 3, 3);
            var shape_line  = client.Draw.DrawLine(0.5, 0.5, 3.5, 3.5);
            var shape_oval1 = client.Draw.DrawOval(0.2, 1, 3.8, 2);
            var shape_oval2 = client.Draw.DrawOval(1.5, 1.5, 2.5, 2.5);

            client.Selection.SelectAllShapes();
            var s0 = client.Selection.GetShapesInSelection();

            Assert.AreEqual(4, s0.Count);

            var g = client.Grouping.GroupSelectedShapes();

            client.Selection.SelectNone();
            client.Selection.SelectAllShapes();

            var s1 = client.Selection.GetShapesInSelection();

            Assert.AreEqual(1, s1.Count);

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

            client.Grouping.UngroupSelectedShapes(targets);
            client.Selection.SelectAllShapes();
            var s2 = client.Selection.GetShapesInSelection();

            Assert.AreEqual(4, s2.Count);
            client.Document.CloseActiveDocument(true);
        }
        public void SetShapeCells(VisioScripting.Models.TargetShapes targets, System.Action <SidSrcWriter, short> apply_cells, bool blast_guards, bool test_circular)
        {
            targets = targets.ResolveShapes(this._client);
            var target_ids = targets.ToShapeIDs();

            this.SetShapeCells(target_ids, apply_cells, blast_guards, test_circular);
        }
Beispiel #8
0
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);

            var dic = this.Client.ConnectionPoint.Get(targets);

            if (this.GetCells)
            {
                this.WriteObject(dic);
                return;
            }

            foreach (var shape_points in dic)
            {
                var shape  = shape_points.Key;
                var points = shape_points.Value;

                int shapeid = shape.ID;

                foreach (var point_cells in points)
                {
                    var cp = new ConnectionPoint(shapeid, point_cells);
                    this.WriteObject(cp);
                }
            }
        }
Beispiel #9
0
        public void DistributeVertical(VisioScripting.Models.TargetShapes targets, VisioScripting.Models.AlignmentVertical valign)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            int shape_count = targets.SetSelectionGetSelectedCount(this._client);

            if (shape_count < 1)
            {
                return;
            }

            IVisio.VisUICmds cmd;
            switch (valign)
            {
            case VisioScripting.Models.AlignmentVertical.Top:
                cmd = IVisio.VisUICmds.visCmdDistributeTop;
                break;

            case VisioScripting.Models.AlignmentVertical.Center: cmd = IVisio.VisUICmds.visCmdDistributeMiddle; break;

            case VisioScripting.Models.AlignmentVertical.Bottom: cmd = IVisio.VisUICmds.visCmdDistributeBottom; break;

            default: throw new System.ArgumentOutOfRangeException();
            }

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

            application.DoCmd((short)cmd);
        }
Beispiel #10
0
        public void DistributeHorizontal(VisioScripting.Models.TargetShapes targets, VisioScripting.Models.AlignmentHorizontal halign)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            int shape_count = targets.SetSelectionGetSelectedCount(this._client);

            if (shape_count < 1)
            {
                return;
            }

            IVisio.VisUICmds cmd;

            switch (halign)
            {
            case VisioScripting.Models.AlignmentHorizontal.Left:
                cmd = IVisio.VisUICmds.visCmdDistributeLeft;
                break;

            case VisioScripting.Models.AlignmentHorizontal.Center:
                cmd = IVisio.VisUICmds.visCmdDistributeCenter;
                break;

            case VisioScripting.Models.AlignmentHorizontal.Right:
                cmd = IVisio.VisUICmds.visCmdDistributeRight;
                break;

            default: throw new System.ArgumentOutOfRangeException();
            }

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

            application.DoCmd((short)cmd);
        }
Beispiel #11
0
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);
            var dic     = this.Client.CustomProp.Get(targets);

            if (this.GetCells)
            {
                this.WriteObject(dic);
                return;
            }

            foreach (var shape_propdic_pair in dic)
            {
                var shape    = shape_propdic_pair.Key;
                var propdic  = shape_propdic_pair.Value;
                int shape_id = shape.ID;
                foreach (var propname_propcells_pair in propdic)
                {
                    string propname  = propname_propcells_pair.Key;
                    var    propcells = propname_propcells_pair.Value;
                    var    cpf       = new CustomProperty(shape_id, propname, propcells);
                    this.WriteObject(cpf);
                }
            }
        }
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);
            var dicof_shape_to_cpdic = this.Client.CustomProperty.GetCustomProperties(targets);

            if (this.GetCells)
            {
                this.WriteObject(dicof_shape_to_cpdic);
                return;
            }

            foreach (var shape_cppdic_pair in dicof_shape_to_cpdic)
            {
                var shape   = shape_cppdic_pair.Key;
                var cpdic   = shape_cppdic_pair.Value;
                int shapeid = shape.ID;
                foreach (var cpname_cpcells_pair in cpdic)
                {
                    string cpname  = cpname_cpcells_pair.Key;
                    var    cpcells = cpname_cpcells_pair.Value;
                    var    cp_obj  = new CustomProperty(shapeid, cpname, cpcells);
                    this.WriteObject(cp_obj);
                }
            }
        }
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);
            var dic     = this.Client.Lock.GetLockCells(targets, CellValueType.Formula);

            this.WriteObject(dic, true);
        }
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);
            var dicof_shape_to_udcelldic = this.Client.UserDefinedCell.GetUserDefinedCells(targets, CellValueType.Formula);

            if (this.GetCells)
            {
                this.WriteObject(dicof_shape_to_udcelldic);
                return;
            }

            foreach (var shape_udcelldic_pair in dicof_shape_to_udcelldic)
            {
                var shape     = shape_udcelldic_pair.Key;
                var udcelldic = shape_udcelldic_pair.Value;
                int shapeid   = shape.ID;
                foreach (var udcellname_udcellcells_pair in udcelldic)
                {
                    string udcellname    = udcellname_udcellcells_pair.Key;
                    var    udcellcells   = udcellname_udcellcells_pair.Value;
                    string udcell_value  = udcellcells.Value.ToString();
                    string udcell_prompt = udcellcells.Prompt.ToString();

                    var udcell_obj = new VisioPowerShell.Models.UserDefinedCell(shapeid, udcellname, udcell_value, udcell_prompt);
                    this.WriteObject(udcell_obj);
                }
            }

            this.WriteObject(dicof_shape_to_udcelldic);
        }
        public void SetPageCells(VisioScripting.Models.TargetShapes targets, System.Action <SidSrcWriter, short> apply_cells, bool blast_guards,
                                 bool test_circular)
        {
            var targets2 = targets.ToShapeIDs();

            this.SetPageCells(targets2, apply_cells, blast_guards, test_circular);
        }
Beispiel #16
0
        public void SetLock(VisioScripting.Models.TargetShapes targets, LockCells lockcells)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            targets = targets.ResolveShapes(this._client);
            if (targets.Shapes.Count < 1)
            {
                return;
            }

            var page            = this._client.Page.Get();
            var target_shapeids = targets.ToShapeIDs();
            var writer          = new SidSrcWriter();

            foreach (int shapeid in target_shapeids.ShapeIDs)
            {
                lockcells.SetFormulas(writer, (short)shapeid);
            }

            using (var undoscope = this._client.Application.NewUndoScope("Set Lock Properties"))
            {
                writer.Commit(page);
            }
        }
Beispiel #17
0
        public void Scripting_Grouping()
        {
            var client = this.GetScriptingClient();

            client.Document.New();
            client.Page.New(new VisioAutomation.Drawing.Size(4, 4), false);

            var shape_rect  = client.Draw.Rectangle(1, 1, 3, 3);
            var shape_line  = client.Draw.Line(0.5, 0.5, 3.5, 3.5);
            var shape_oval1 = client.Draw.Oval(0.2, 1, 3.8, 2);
            var shape_oval2 = client.Draw.Oval(new VisioAutomation.Drawing.Point(2, 2), 0.5);

            client.Selection.SelectAll();
            var s0 = client.Selection.GetShapes();

            Assert.AreEqual(4, s0.Count);

            var g = client.Grouping.Group();

            client.Selection.SelectNone();
            client.Selection.SelectAll();

            var s1 = client.Selection.GetShapes();

            Assert.AreEqual(1, s1.Count);

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

            client.Grouping.Ungroup(targets);
            client.Selection.SelectAll();
            var s2 = client.Selection.GetShapes();

            Assert.AreEqual(4, s2.Count);
            client.Document.Close(true);
        }
Beispiel #18
0
        public IDictionary <IVisio.Shape, CustomPropertyDictionary> Get(VisioScripting.Models.TargetShapes targets)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            var prop_dic = new Dictionary <IVisio.Shape, CustomPropertyDictionary>();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(prop_dic);
            }

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

            var list_custom_props = CustomPropertyHelper.Get(page, targets.Shapes);

            for (int i = 0; i < targets.Shapes.Count; i++)
            {
                var shape = targets.Shapes[i];
                var props = list_custom_props[i];
                prop_dic[shape] = props;
            }

            return(prop_dic);
        }
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);
            var t       = this.Client.Text.Get(targets);

            this.WriteObject(t);
        }
Beispiel #20
0
        public void Set(VisioScripting.Models.TargetShapes targets, string name, CustomPropertyCells customprop)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Application.NewUndoScope("Set Custom Property"))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
Beispiel #21
0
        public void Nudge(VisioScripting.Models.TargetShapes targets, double dx, double dy)
        {
            if (dx == 0.0 && dy == 0.0)
            {
                return;
            }

            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            int shape_count = targets.SetSelectionGetSelectedCount(this._client);

            if (shape_count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Application.NewUndoScope("Nudge"))
            {
                var selection = this._client.Selection.Get();
                var unitcode  = Microsoft.Office.Interop.Visio.VisUnitCodes.visInches;

                // Move method: http://msdn.microsoft.com/en-us/library/ms367549.aspx
                selection.Move(dx, dy, unitcode);
            }
        }
        protected override void ProcessRecord()
        {
            var target_shapes = this.Shapes ?? this.Client.Selection.GetShapes();
            var targets       = new VisioScripting.Models.TargetShapes(target_shapes);

            this.Client.ShapeSheet.SetShapeCells(targets, this.ApplyCells, this.BlastGuards, this.TestCircular);
        }
        public void SetPageCells(VisioScripting.Models.TargetShapes targets, Dictionary <string, string> hashtable, bool blast_guards,
                                 bool test_circular)
        {
            var targets2 = targets.ToShapeIDs();

            this.SetPageCells(targets2, hashtable, blast_guards, test_circular);
        }
Beispiel #24
0
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);

            if (this.NudgeX != 0.0 || this.NudgeY != 0.0)
            {
                this.Client.Arrange.Nudge(targets, this.NudgeX, this.NudgeY);
            }

            if (this.DistributeHorizontal)
            {
                this.Client.Distribute.DistributeOnAxis(targets, VisioScripting.Models.Axis.XAxis);
            }

            if (this.DistributeVertical)
            {
                this.Client.Distribute.DistributeOnAxis(targets, VisioScripting.Models.Axis.YAxis);
            }

            if (this.AlignVertical.HasValue)
            {
                this.Client.Align.AlignVertical(targets, this.AlignVertical.Value);
            }

            if (this.AlignHorizontal.HasValue)
            {
                this.Client.Align.AlignHorizontal(targets, this.AlignHorizontal.Value);
            }
        }
        public void SetShapeCells(VisioScripting.Models.TargetShapes targets, Dictionary <string, string> hashtable, bool blast_guards, bool test_circular)
        {
            targets = targets.ResolveShapes(this._client);
            var target_ids = targets.ToShapeIDs();

            this.SetShapeCells(target_ids, hashtable, blast_guards, test_circular);
        }
        public void Scripting_Distribute()
        {
            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.DistributeHorizontal(targets, VisioScripting.Models.AlignmentHorizontal.Center);

            var shapeids = new[] { s1.ID, s2.ID, s3.ID };

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

            client.Document.Close(true);
        }
Beispiel #27
0
        public List <int> Add(VisioScripting.Models.TargetShapes targets, ControlCells ctrl)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }


            var control_indices = new List <int>();

            using (var undoscope = this._client.Application.NewUndoScope("Add Control"))
            {
                foreach (var shape in targets.Shapes)
                {
                    int ci = ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
        public void Scripting_ShapeSheet_SetNoShapes()
        {
            var client = this.GetScriptingClient();

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

            var s1 = client.Draw.DrawRectangle(1, 1, 1.25, 1.5);
            var s2 = client.Draw.DrawRectangle(2, 3, 2.5, 3.5);
            var s3 = client.Draw.DrawRectangle(4.5, 2.5, 6, 3.5);

            client.Selection.SelectNone();

            var shapes   = new VisioScripting.Models.TargetShapes(s1, s2, s3);
            var shapeids = shapes.ToShapeIDs();
            var page     = client.Page.GetActivePage();
            var writer   = client.ShapeSheet.GetWriterForPage(page);

            foreach (var shapeid in shapeids.ShapeIDs)
            {
                writer.SetFormula((short)shapeid, VA.ShapeSheet.SrcConstants.XFormPinX, "1.0");
            }

            writer.Commit();

            client.Document.CloseActiveDocument(true);
        }
        protected override void ProcessRecord()
        {
            var target_shapes = this.Shapes ?? this.Client.Selection.GetShapes();
            var targets       = new VisioScripting.Models.TargetShapes(target_shapes);

            var dic = Set_VisioPageCell.CellHashtableToDictionary(this.Hashtable);

            this.Client.ShapeSheet.SetShapeCells(targets, dic, this.BlastGuards, this.TestCircular);
        }
Beispiel #30
0
        protected override void ProcessRecord()
        {
            var targets = new VisioScripting.Models.TargetShapes(this.Shapes);

            if (this.Font != null)
            {
                this.Client.Text.SetFont(targets, this.Font);
            }
        }