public void Scripting_Drop_Many() { var pagesize = new VA.Geometry.Size(10, 10); var client = this.GetScriptingClient(); // Create the Page client.Document.NewDocument(); client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false); // Load the stencils and find the masters var basic_stencil = client.Document.OpenStencilDocument("Basic_U.VSS"); var stencil_targetdoc = new VisioScripting.TargetDocument(basic_stencil); var m1 = client.Master.GetMaster(stencil_targetdoc, "Rectangle"); var m2 = client.Master.GetMaster(stencil_targetdoc, "Ellipse"); // Drop the Shapes var masters = new[] { m1, m2 }; var xys = new[] { 1.0, 2.0, 3.0, 4.0, 1.5, 4.5, 5.7, 2.4 }; var points = VA.Geometry.Point.FromDoubles(xys).ToList(); client.Master.DropMasters(VisioScripting.TargetPage.Auto, masters, points); // Verify var application = client.Application.GetApplication(); Assert.AreEqual(4, application.ActivePage.Shapes.Count); // Cleanup client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto); }
protected override void ProcessRecord() { var targetdoc = new VisioScripting.TargetDocument(this.Document); targetdoc.Resolve(this.Client); bool master_specified = this.Name != null; bool doc_specified = this.Document != null; if (master_specified) { foreach (var name in this.Name) { var masters = this.Client.Master.FindMasters(targetdoc, name); this.WriteObject(masters, true); } } else { // master name is not specified if (doc_specified) { this.WriteVerbose("Get all masters from specified document"); var masters = this.Client.Master.GetMasters(targetdoc); this.WriteObject(masters, true); } else { this.WriteVerbose("Get all masters from active document"); var masters = this.Client.Master.GetMasters(targetdoc); this.WriteObject(masters, true); } } }
public void Scripting_Drop_Master() { var pagesize = new VA.Geometry.Size(4, 4); var client = this.GetScriptingClient(); // Create the page client.Document.NewDocument(); client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false); // Load the stencils and find the masters var basic_stencil = client.Document.OpenStencilDocument("Basic_U.VSS"); var stencil_targetdoc = new VisioScripting.TargetDocument(basic_stencil); var master = client.Master.GetMaster(stencil_targetdoc, "Rectangle"); // Frop the Shapes client.Master.DropMaster(VisioScripting.TargetPage.Auto, master, new VA.Geometry.Point(2, 2)); // Verify var application = client.Application.GetApplication(); var active_page = application.ActivePage; var shapes = active_page.Shapes; Assert.AreEqual(1, shapes.Count); // cleanup client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto); }
public void Scripting_CanCloseUnsavedDrawings() { var client = this.GetScriptingClient(); client.Document.CloseAllDocumentsWithoutSaving(); Assert.IsFalse(client.Document.HasActiveDocument); var doc1 = client.Document.NewDocument(); Assert.IsTrue(client.Document.HasActiveDocument); Assert.IsFalse(client.Selection.SelectionContainsShapes()); client.Draw.DrawRectangle(0, 0, 1, 1); Assert.IsTrue(client.Document.HasActiveDocument); Assert.IsTrue(client.Selection.SelectionContainsShapes()); Assert.IsTrue(client.Selection.SelectionContainsShapes(1)); Assert.IsFalse(client.Selection.SelectionContainsShapes(2)); client.Draw.DrawRectangle(2, 2, 3, 3); client.Selection.SelectAllShapes(); Assert.IsTrue(client.Document.HasActiveDocument); Assert.IsTrue(client.Selection.SelectionContainsShapes()); Assert.IsTrue(client.Selection.SelectionContainsShapes(1)); Assert.IsTrue(client.Selection.SelectionContainsShapes(2)); client.Selection.SelectNone(); Assert.IsTrue(client.Document.HasActiveDocument); Assert.IsFalse(client.Selection.SelectionContainsShapes()); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
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 targetshapes = new VisioScripting.TargetShapes(s1, s2, s3); var targetshapeids = targetshapes.ToShapeIDs(); var page = new VisioScripting.TargetPage(); var writer = client.ShapeSheet.GetWriterForPage(page); foreach (var shapeid in targetshapeids) { writer.SetFormula((short)shapeid, VA.ShapeSheet.SrcConstants.XFormPinX, "1.0"); } writer.Commit(); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public IVisio.Page NewPage(VisioScripting.TargetDocument targetdoc, VisioAutomation.Geometry.Size?size, bool isbackgroundpage) { targetdoc = targetdoc.ResolveToDocument(this._client); var pages = targetdoc.Document.Pages; IVisio.Page new_page; using (var undoscope = this._client.Undo.NewUndoScope(nameof(NewPage))) { new_page = pages.Add(); if (size.HasValue) { var targetpages = new TargetPages(new_page); this.SetPageSize(targetpages, size.Value); } if (isbackgroundpage) { new_page.Background = 1; } } return(new_page); }
public void Scripting_Test_Export_Selection_SVGHTML() { var client = this.GetScriptingClient(); var page_size = new VisioAutomation.Geometry.Size(10, 5); var doc = client.Document.NewDocument(page_size); var page1 = doc.Pages[1]; var s1 = page1.DrawRectangle(0, 0, 1, 1); var s2 = page1.DrawRectangle(1, 0, 2, 1); var s3 = page1.DrawRectangle(0, 1, 1, 2); var s4 = page1.DrawRectangle(1, 1, 2, 2); client.Selection.SelectAllShapes(); string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(Scripting_Test_Export_Selection_SVGHTML), ".html"); if (File.Exists(output_filename)) { File.Delete(output_filename); } client.ExportSelection.ExportSelectionToHtml(output_filename); AssertUtil.FileExists(output_filename); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Drop_Container_Master_Object() { var pagesize = new VA.Geometry.Size(4, 4); var client = this.GetScriptingClient(); // Create the page client.Document.NewDocument(); client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false); var application = client.Application.GetApplication(); var active_page = application.ActivePage; // Load the stencils and find the masters var basic_stencil = client.Document.OpenStencilDocument("Basic_U.VSS"); var stencil_targetdoc = new VisioScripting.TargetDocument(basic_stencil); var master = client.Master.GetMaster(stencil_targetdoc, "Rectangle"); // Drop the rectangle client.Master.DropMaster(VisioScripting.TargetPage.Auto, master, new VA.Geometry.Point(2, 2)); // Select the rectangle... it should already be selected, but just make sure client.Selection.SelectAllShapes(VisioScripting.TargetWindow.Auto); // Drop the container... since the rectangle is selected... it will automatically make it a member of the container var app = active_page.Application; var ver = client.Application.ApplicationVersion; var cont_master_name = ver.Major >= 15 ? "Plain" : "Container 1"; var stencil_type = IVisio.VisBuiltInStencilTypes.visBuiltInStencilContainers; var measurement_system = IVisio.VisMeasurementSystem.visMSUS; var containers_file = app.GetBuiltInStencilFile(stencil_type, measurement_system); var containers_doc = app.Documents.OpenStencil(containers_file); var masters = containers_doc.Masters; var container_master = masters.ItemU[cont_master_name]; var dropped_container = client.Container.DropContainerMaster(VisioScripting.TargetPage.Auto, container_master); // Verify var shapes = active_page.Shapes; // There should be two shapes... the rectangle and the container Assert.AreEqual(2, shapes.Count); // Verify that we did indeed drop a container var results_dic = VisioAutomation.Shapes.UserDefinedCellHelper.GetDictionary(dropped_container, VA.ShapeSheet.CellValueType.Result); Assert.IsTrue(results_dic.ContainsKey("msvStructureType")); var prop = results_dic["msvStructureType"]; Assert.AreEqual("Container", prop.Value.Value); // cleanup client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto); }
public void DrawVAScriptingAPIDiagram() { var client = this.GetScriptingClient(); var doc = client.Developer.DrawScriptingDocumentation(); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void DrawVANamespaceDiagram() { var client = this.GetScriptingClient(); var doc = client.Developer.DrawNamespaces(); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
protected override void ProcessRecord() { var targetdoc = new VisioScripting.TargetDocument(this.Document); this.Client.Output.WriteVerbose("Creating a new page"); var page = this.Client.Page.NewPage(targetdoc, null, false); if (this.Name != null) { if (this.Name.Length == 0) { throw new System.ArgumentException("Name can't be empty"); } string n = this.Name.Trim(); if (n.Length == 0) { throw new System.ArgumentException("Name can't be empty"); } this.Client.Output.WriteVerbose("Setting page name \"{0}\"", n); page.NameU = n; } if (this.Width > 0 || this.Height > 0) { // width and height are used and there isn't a PageCells object // then create one this.Cells = this.Cells ?? new Models.PageCells(); if (this.Width > 0) { this.Cells.PageWidth = this.Width.ToString(CultureInfo.InvariantCulture); } if (this.Height > 0) { this.Cells.PageHeight = this.Height.ToString(CultureInfo.InvariantCulture); } } if (this.Cells != null) { var targetpage_shapesheet = page.PageSheet; int targetpage_shapesheetid = targetpage_shapesheet.ID; var writer = new VisioAutomation.ShapeSheet.Writers.SidSrcWriter(); writer.BlastGuards = true; writer.TestCircular = true; this.Cells.Apply(writer, (short)targetpage_shapesheetid); this.Client.Output.WriteVerbose("Updating Cells for new page"); writer.Commit(page, VisioAutomation.ShapeSheet.CellValueType.Formula); } this.WriteObject(page); }
public void Scripting_Connects_Scenario_1() { var client = this.GetScriptingClient(); client.Document.NewDocument(); var pagesize = new VA.Geometry.Size(4, 4); client.Page.NewPage(pagesize, 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(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); client.Document.OpenStencilDocument("basic_u.vss"); var connec_stencil = client.Document.OpenStencilDocument("connec_u.vss"); var connec_tdoc = new VisioScripting.TargetDocument(connec_stencil); var master = client.Master.GetMaster(connec_tdoc, "Dynamic Connector"); var undirected_connectors = client.Connection.ConnectShapes(new [] { s1, s2 }, new [] { s2, s3 }, master); var options1 = new VisioAutomation.DocumentAnalysis.ConnectionAnalyzerOptions(); options1.NoArrowsHandling = NoArrowsHandling.ExcludeEdge; var directed_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options1); Assert.AreEqual(0, directed_edges0.Count); var options2 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions(); options2.NoArrowsHandling = NoArrowsHandling.TreatEdgeAsBidirectional; var directed_edges1 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options2); Assert.AreEqual(4, directed_edges1.Count); var options3 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions(); options3.DirectionSource = DirectionSource.UseConnectionOrder; var undirected_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options3); Assert.AreEqual(2, undirected_edges0.Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Controls_Scenarios() { var client = this.GetScriptingClient(); client.Document.NewDocument(); client.Page.NewPage(new VisioAutomation.Geometry.Size(4, 4), false); var s1 = client.Draw.DrawRectangle(1, 1, 1.5, 1.5); var s2 = client.Draw.DrawRectangle(2, 3, 2.5, 3.5); var s3 = client.Draw.DrawRectangle(1.5, 3.5, 2, 4.0); client.Selection.SelectNone(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var targetshapes = new VisioScripting.TargetShapes(); var controls0 = client.Control.GetControls(targetshapes, CellValueType.Formula); int found_controls = controls0.Count; Assert.AreEqual(3, controls0.Count); Assert.AreEqual(0, controls0[s1].Count); Assert.AreEqual(0, controls0[s2].Count); Assert.AreEqual(0, controls0[s3].Count); var ctrl = new ControlCells(); ctrl.X = "Width*0.5"; ctrl.Y = "0"; client.Control.AddControlToShapes(targetshapes, ctrl); var controls1 = client.Control.GetControls(targetshapes, CellValueType.Formula); Assert.AreEqual(3, controls1.Count); Assert.AreEqual(1, controls1[s1].Count); Assert.AreEqual(1, controls1[s2].Count); Assert.AreEqual(1, controls1[s3].Count); client.Control.DeleteControlWithIndex(targetshapes, 0); var controls2 = client.Control.GetControls(targetshapes, CellValueType.Formula); Assert.AreEqual(3, controls0.Count); Assert.AreEqual(0, controls2[s1].Count); Assert.AreEqual(0, controls2[s2].Count); Assert.AreEqual(0, controls2[s3].Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Connects_Scenario_3() { var client = this.GetScriptingClient(); client.Document.NewDocument(); var s1 = client.Draw.DrawRectangle(1, 1, 2, 2); var s2 = client.Draw.DrawRectangle(4, 4, 5, 5); client.Connection.ConnectShapes(new[] { s1 }, new[] { s2 }, null); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
protected override void ProcessRecord() { if (this.ActivePage) { var page = this.Client.Page.GetActivePage(); this.WriteObject(page); return; } var targetdoc = new VisioScripting.TargetDocument(this.Document).Resolve(this.Client); var pages = this.Client.Page.FindPagesByName(targetdoc, this.Name, this.Type); this.WriteObject(pages, true); }
public void Scripting_Hyperlinks_Scenarios() { var client = this.GetScriptingClient(); client.Document.NewDocument(); client.Page.NewPage(new VisioAutomation.Geometry.Size(4, 4), false); var s1 = client.Draw.DrawRectangle(1, 1, 1.5, 1.5); var s2 = client.Draw.DrawRectangle(2, 3, 2.5, 3.5); var s3 = client.Draw.DrawRectangle(1.5, 3.5, 2, 4.0); client.Selection.SelectNone(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var targetshapes = new VisioScripting.TargetShapes(); var hyperlinks0 = client.Hyperlink.GetHyperlinks(targetshapes, VASS.CellValueType.Formula); Assert.AreEqual(3, hyperlinks0.Count); Assert.AreEqual(0, hyperlinks0[s1].Count); Assert.AreEqual(0, hyperlinks0[s2].Count); Assert.AreEqual(0, hyperlinks0[s3].Count); var hyperlink = new VA.Shapes.HyperlinkCells(); hyperlink.Address = "http://www.microsoft.com"; client.Hyperlink.AddHyperlink(targetshapes, hyperlink); var hyperlinks1 = client.Hyperlink.GetHyperlinks(targetshapes, VASS.CellValueType.Formula); Assert.AreEqual(3, hyperlinks1.Count); Assert.AreEqual(1, hyperlinks1[s1].Count); Assert.AreEqual(1, hyperlinks1[s2].Count); Assert.AreEqual(1, hyperlinks1[s3].Count); client.Hyperlink.DeleteHyperlinkAtIndex(targetshapes, 0); var hyperlinks2 = client.Hyperlink.GetHyperlinks(targetshapes, VASS.CellValueType.Formula); Assert.AreEqual(3, hyperlinks0.Count); Assert.AreEqual(0, hyperlinks2[s1].Count); Assert.AreEqual(0, hyperlinks2[s2].Count); Assert.AreEqual(0, hyperlinks2[s3].Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Undo_Scenarios() { var client = this.GetScriptingClient(); var page_size = new VisioAutomation.Geometry.Size(8.5, 11); var drawing = client.Document.NewDocument(page_size); var page = client.Page.NewPage(page_size, false); Assert.AreEqual(0, page.Shapes.Count); page.DrawRectangle(1, 1, 3, 3); Assert.AreEqual(1, page.Shapes.Count); client.Undo.UndoLastAction(); Assert.AreEqual(0, page.Shapes.Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void SetActivePage(VisioScripting.TargetDocument targetdoc, Models.PageRelativePosition flags) { targetdoc = targetdoc.ResolveToDocument(this._client); var docpages = targetdoc.Document.Pages; if (docpages.Count < 2) { return; } var pages = docpages; var cmdtarget = this._client.GetCommandTarget(CommandTargetFlags.RequirePage); this._go_to_page(pages, flags, cmdtarget); }
public void Scripting_Distribute_With_Spacing() { var client = this.GetScriptingClient(); var pagesize = new VA.Geometry.Size(4, 4); client.Document.NewDocument(); client.Page.NewPage(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.DrawRectangle(r1); var s2 = client.Draw.DrawRectangle(r2); var s3 = client.Draw.DrawRectangle(r3); client.Selection.SelectNone(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var targetshapes = new VisioScripting.TargetShapes(); client.Distribute.DistributeSelectionOnAxis(targetshapes, VisioScripting.Models.Axis.XAxis, 0.25); client.Distribute.DistributeSelectionOnAxis(targetshapes, VisioScripting.Models.Axis.YAxis, 1.0); var shapes = new[] { s1, s2, s3 }; var shapeids = shapes.Select(s => (int)s.ID16).ToList(); var out_xfrms = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Result); var out_positions = out_xfrms.Select(xfrm => TestExtensions.ToPoint(xfrm.PinX.Value, xfrm.PinY.Value)).ToArray(); Assert.AreEqual(1.25, out_positions[0].X); Assert.AreEqual(1.25, out_positions[0].Y); Assert.AreEqual(2.25, out_positions[1].X); Assert.AreEqual(3.00, out_positions[1].Y); Assert.AreEqual(3.75, out_positions[2].X); Assert.AreEqual(5.25, out_positions[2].Y); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Selection_Scenarios() { var client = this.GetScriptingClient(); var page_size = new VisioAutomation.Geometry.Size(10, 5); var doc = client.Document.NewDocument(page_size); var page1 = doc.Pages[1]; var app = page1.Application; var s1 = page1.DrawRectangle(0, 0, 1, 1); var s2 = page1.DrawRectangle(1, 0, 2, 1); var s3 = page1.DrawRectangle(0, 1, 1, 2); var s4 = page1.DrawRectangle(1, 1, 2, 2); var active_window = app.ActiveWindow; var selection = active_window.Selection; var x1 = selection.ToEnumerable().ToDictionary(s => s); Assert.AreEqual(1, x1.Count); Assert.IsTrue(x1.ContainsKey(s4)); client.Selection.InvertSelection(); var x2 = active_window.Selection.ToEnumerable().ToDictionary(s => s); Assert.AreEqual(3, x2.Count); Assert.IsTrue(x2.ContainsKey(s1)); Assert.IsTrue(x2.ContainsKey(s2)); Assert.IsTrue(x2.ContainsKey(s3)); Assert.IsTrue(!x2.ContainsKey(s4)); active_window.SelectAll(); //app.ActiveWindows.Selection.SelectAll() selects 3 items var x3 = active_window.Selection.ToEnumerable().ToDictionary(s => s); Assert.AreEqual(4, x3.Count); active_window.DeselectAll(); //app.ActiveWindows.Selection.DeselectAll() keeps all 4 selection var x4 = active_window.Selection.ToEnumerable().ToDictionary(s => s); Assert.AreEqual(0, x4.Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
protected override void ProcessRecord() { if (this.ActivePage) { var page_active = this.Client.Page.GetActivePage(); this.WriteObject(page_active); return; } // If the active page is not specified then work on all the pages in a document (user-specified or auto) var targetdoc = new VisioScripting.TargetDocument(this.Document); // First, the ID case if (this.ID != null) { var t = targetdoc.ResolveToDocument(this.Client); foreach (var id in this.ID) { var page = t.Document.Pages[id]; this.WriteObject(page); } return; } // Then, handle the name case if (this.Name == null) { var pages_by_name = this.Client.Page.FindPagesInDocument(targetdoc, null); this.WriteObject(pages_by_name, true); return; } var list_page = new List <IVisio.Page>(); foreach (var name in this.Name) { var pages_by_name = this.Client.Page.FindPagesInDocument(targetdoc, name); list_page.AddRange(pages_by_name); } this.WriteObject(list_page, true); }
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); }
public void Scripting_Distribute() { var client = this.GetScriptingClient(); var pagesize = new VA.Geometry.Size(4, 4); client.Document.NewDocument(); client.Page.NewPage(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.DrawRectangle(r1); var s2 = client.Draw.DrawRectangle(r2); var s3 = client.Draw.DrawRectangle(r3); client.Selection.SelectNone(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var targetshapes = new VisioScripting.TargetShapes(); client.Distribute.DistributeShapesHorizontal(targetshapes, VisioScripting.Models.AlignmentHorizontal.Center); var shapes = new[] { s1, s2, s3 }; var shapeids = shapes.Select(s => (int)s.ID16).ToList(); VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Formula); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Nudge2() { var client = this.GetScriptingClient(); client.Document.NewDocument(); client.Page.NewPage(new VA.Geometry.Size(4, 4), 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.DrawRectangle(r1); var s2 = client.Draw.DrawRectangle(r2); var s3 = client.Draw.DrawRectangle(r3); client.Selection.SelectNone(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); client.Arrange.NudgeSelection(0.50, -0.25); var shapes = new[] { s1, s2, s3 }; var shapeids = shapes.Select(s => (int)s.ID16).ToList(); var xforms = VisioAutomation.Shapes.ShapeXFormCells.GetCells(client.Page.GetActivePage(), shapeids, VA.ShapeSheet.CellValueType.Result); AssertUtil.AreEqual((1.75, 1), xforms[0].GetPinPosResult(), 0.00001); AssertUtil.AreEqual((3, 2.25), xforms[1].GetPinPosResult(), 0.00001); AssertUtil.AreEqual((5.25, 4.5), xforms[2].GetPinPosResult(), 0.00001); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
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 targetshapes = new VisioScripting.TargetShapes(); client.Grouping.UngroupSelectedShapes(targetshapes); client.Selection.SelectAllShapes(); var s2 = client.Selection.GetShapesInSelection(); Assert.AreEqual(4, s2.Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Draw_Grid() { var origin = new VisioAutomation.Geometry.Point(0, 4); var pagesize = new VisioAutomation.Geometry.Size(4, 4); var cellsize = new VisioAutomation.Geometry.Size(0.5, 0.25); int cols = 3; int rows = 6; // Create the Page var client = this.GetScriptingClient(); client.Document.NewDocument(); client.Page.NewPage(VisioScripting.TargetDocument.Auto, pagesize, false); // Find the stencil and master var stencildoc = client.Document.OpenStencilDocument("basic_u.vss"); var stencil_targetdoc = new VisioScripting.TargetDocument(stencildoc); var master = client.Master.GetMaster(stencil_targetdoc, "Rectangle"); // Draw the grid var page = client.Page.GetActivePage(); var grid = new GRID.GridLayout(cols, rows, cellsize, master); grid.Origin = origin; grid.Render(page); // Verify int total_shapes_expected = cols * rows; var shapes = page.Shapes.ToList(); int total_shapes_actual = shapes.Count; Assert.AreEqual(total_shapes_expected, total_shapes_actual); // Cleanup client.Document.CloseDocument(VisioScripting.TargetDocuments.Auto); }
public void Scripting_ConnectionPoints_Scenarios() { var client = this.GetScriptingClient(); client.Document.NewDocument(); client.Page.NewPage(new VisioAutomation.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(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var indices0 = client.ConnectionPoint.AddConnectionPoint("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 targetshapes = new VisioScripting.TargetShapes(); var dic = client.ConnectionPoint.GetConnectionPoints(targetshapes); 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.DeleteConnectionPointAtIndex(targetshapes, 0); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_CustomProps_Scenarios() { 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(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); var targetshapes = new VisioScripting.TargetShapes(); var prop_dic0 = client.CustomProperty.GetCustomProperties(targetshapes); Assert.AreEqual(3, prop_dic0.Count); Assert.AreEqual(0, prop_dic0[s1].Count); Assert.AreEqual(0, prop_dic0[s2].Count); Assert.AreEqual(0, prop_dic0[s3].Count); var cp = new CustomPropertyCells(); cp.Value = "\"BAR\""; client.CustomProperty.SetCustomProperty(targetshapes, "FOO", cp); var prop_dic1 = client.CustomProperty.GetCustomProperties(targetshapes); Assert.AreEqual(3, prop_dic1.Count); Assert.AreEqual(1, prop_dic1[s1].Count); Assert.AreEqual(1, prop_dic1[s2].Count); Assert.AreEqual(1, prop_dic1[s3].Count); var cp1 = prop_dic1[s1]["FOO"]; var cp2 = prop_dic1[s2]["FOO"]; var cp3 = prop_dic1[s3]["FOO"]; Assert.AreEqual("\"BAR\"", cp1.Value.Value); Assert.AreEqual("\"BAR\"", cp2.Value.Value); Assert.AreEqual("\"BAR\"", cp3.Value.Value); var hasprops0 = client.CustomProperty.ContainCustomPropertyWithName(targetshapes, "FOO"); Assert.IsTrue(hasprops0.All(v => v == true)); client.CustomProperty.DeleteCustomPropertyWithName(targetshapes, "FOO"); var prop_dic2 = client.CustomProperty.GetCustomProperties(targetshapes); Assert.AreEqual(3, prop_dic2.Count); Assert.AreEqual(0, prop_dic2[s1].Count); Assert.AreEqual(0, prop_dic2[s2].Count); Assert.AreEqual(0, prop_dic2[s3].Count); var hasprops1 = client.CustomProperty.ContainCustomPropertyWithName(targetshapes, "FOO"); Assert.IsTrue(hasprops1.All(v => v == false)); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }
public void Scripting_Connects_Scenario_0() { var client = this.GetScriptingClient(); client.Document.NewDocument(); var pagesize = new VA.Geometry.Size(4, 4); client.Page.NewPage(pagesize, 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(); client.Selection.SelectShapesById(s1); client.Selection.SelectShapesById(s2); client.Selection.SelectShapesById(s3); client.Document.OpenStencilDocument("basic_u.vss"); var connec_stencil = client.Document.OpenStencilDocument("connec_u.vss"); var tdoc = new VisioScripting.TargetDocument(connec_stencil); var master = client.Master.GetMaster(tdoc, "Dynamic Connector"); var fromshapes = new [] { s1, s2 }; var toshapes = new [] { s2, s3 }; var directed_connectors = client.Connection.ConnectShapes(fromshapes, toshapes, master); client.Selection.SelectNone(); client.Selection.SelectShapes(directed_connectors); var page = new VisioScripting.TargetPage(); var writer = client.ShapeSheet.GetWriterForPage(page); var shapes = client.Selection.GetShapesInSelection(); foreach (var shape in shapes) { writer.SetFormula(shape.ID16, VA.ShapeSheet.SrcConstants.LineEndArrow, "13"); } writer.Commit(); var options0 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions(); options0.DirectionSource = DirectionSource.UseConnectionOrder; var undirected_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options0); Assert.AreEqual(2, undirected_edges0.Count); var options1 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions(); options1.NoArrowsHandling = NoArrowsHandling.ExcludeEdge; var options2 = new VA.DocumentAnalysis.ConnectionAnalyzerOptions(); options2.NoArrowsHandling = NoArrowsHandling.TreatEdgeAsBidirectional; var directed_edges0 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options1); Assert.AreEqual(2, directed_edges0.Count); var directed_edges1 = client.Connection.GetDirectedEdgesOnPage(new VisioScripting.TargetPage(), options2); Assert.AreEqual(2, directed_edges1.Count); var targetdoc = new VisioScripting.TargetDocument(); client.Document.CloseDocument(targetdoc, true); }