public void SetShapeCells(VisioScripting.Models.TargetShapeIDs targets, Dictionary <string, string> hashtable, bool blast_guards, bool test_circular) { var writer = new SidSrcWriter(); writer.BlastGuards = blast_guards; writer.TestCircular = test_circular; var cellmap = VisioScripting.Models.CellSrcDictionary.GetCellMapForShapes(); var valuemap = new VisioScripting.Models.CellValueDictionary(cellmap, hashtable); foreach (var shape_id in targets.ShapeIDs) { foreach (var cellname in valuemap.Keys) { string cell_value = valuemap[cellname]; var cell_src = valuemap.GetSrc(cellname); writer.SetFormula((short)shape_id, cell_src, cell_value); } } var surface = this._client.ShapeSheet.GetShapeSheetSurface(); this._client.WriteVerbose("BlastGuards: {0}", blast_guards); this._client.WriteVerbose("TestCircular: {0}", test_circular); this._client.WriteVerbose("Number of Shapes : {0}", targets.ShapeIDs.Count); using (var undoscope = this._client.Application.NewUndoScope("Set Shape Cells")) { this._client.WriteVerbose("Start Update"); writer.Commit(surface); this._client.WriteVerbose("End Update"); } }
public void SetLock(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((short)shapeid, writer); } using (var undoscope = this._client.Application.NewUndoScope("Set Lock Properties")) { writer.Commit(page); } }
public void SetShapeCells(VisioScripting.Models.TargetShapeIDs targets, System.Action <SidSrcWriter, short> apply_cells, bool blast_guards, bool test_circular) { var writer = new SidSrcWriter(); writer.BlastGuards = blast_guards; writer.TestCircular = test_circular; foreach (var shape_id in targets.ShapeIDs) { apply_cells(writer, (short)shape_id); } var surface = this._client.ShapeSheet.GetShapeSheetSurface(); this._client.WriteVerbose("BlastGuards: {0}", blast_guards); this._client.WriteVerbose("TestCircular: {0}", test_circular); this._client.WriteVerbose("Number of Shapes : {0}", targets.ShapeIDs.Count); using (var undoscope = this._client.Application.NewUndoScope("Set Shape Cells")) { this._client.WriteVerbose("Start Update"); writer.Commit(surface); this._client.WriteVerbose("End Update"); } }
private void connect(IVisio.Shape a, IVisio.Shape b, bool a_arrow, bool b_arrow) { var page = a.ContainingPage; var connectors_stencil = page.Application.Documents.OpenStencil("connec_u.vss"); var connectors_masters = connectors_stencil.Masters; var dcm = connectors_masters["Dynamic Connector"]; var drop_point = new VADRAW.Point(-2, -2); var c1 = page.Drop(dcm, drop_point); ConnectorHelper.ConnectShapes(a, b, c1); //a.AutoConnect(b, connect_dir_none, null); if (a_arrow || b_arrow) { var writer = new SidSrcWriter(); if (a_arrow) { writer.SetFormula(c1.ID16, VASS.SrcConstants.LineBeginArrow, "13"); } if (b_arrow) { writer.SetFormula(c1.ID16, VASS.SrcConstants.LineEndArrow, "13"); } writer.Commit(page); } }
public void SetSize(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); } }
public void ToogleCase(VisioScripting.Models.TargetShapes targets) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return; } var application = this._client.Application.Get(); using (var undoscope = this._client.Application.NewUndoScope("Toggle Shape Text Case")) { var shapeids = targets.Shapes.Select(s => s.ID).ToList(); var page = application.ActivePage; // Store all the formatting var formats = VisioAutomation.Text.TextFormat.GetFormat(page, shapeids); // Change the text - this will wipe out all the character and paragraph formatting foreach (var shape in targets.Shapes) { string t = shape.Text; if (t.Length < 1) { continue; } shape.Text = VisioScripting.Helpers.TextHelper.toggle_case(t); } // Now restore all the formatting - based on any initial formatting from the text var writer = new SidSrcWriter(); for (int i = 0; i < targets.Shapes.Count; i++) { var format = formats[i]; if (format.CharacterFormats.Count > 0) { var fmt = format.CharacterFormats[0]; fmt.SetFormulas((short)shapeids[i], writer, 0); } if (format.ParagraphFormats.Count > 0) { var fmt = format.ParagraphFormats[0]; fmt.SetFormulas((short)shapeids[i], writer, 0); } } writer.Commit(page); } }
private static void ModifyPinPositions(IVisio.Page page, IList <int> sorted_shape_ids, List <VisioAutomation.Drawing.Point> newpositions) { var writer = new SidSrcWriter(); for (int i = 0; i < newpositions.Count; i++) { writer.SetFormula((short)sorted_shape_ids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormPinX, newpositions[i].X); writer.SetFormula((short)sorted_shape_ids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormPinY, newpositions[i].Y); } writer.Commit(page); }
private static void ModifySizes(IVisio.Page page, IList <int> sorted_shape_ids, List <VisioAutomation.Drawing.Size> newsizes) { var writer = new SidSrcWriter(); for (int i = 0; i < newsizes.Count; i++) { writer.SetFormula((short)sorted_shape_ids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, newsizes[i].Width); writer.SetFormula((short)sorted_shape_ids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, newsizes[i].Height); } writer.Commit(page); }
private static void _modify_pin_positions(IVisio.Page page, IList <int> sorted_shapeids, List <VisioAutomation.Geometry.Point> newpositions) { var writer = new SidSrcWriter(); for (int i = 0; i < newpositions.Count; i++) { writer.SetValue((short)sorted_shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormPinX, newpositions[i].X); writer.SetValue((short)sorted_shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormPinY, newpositions[i].Y); } writer.Commit(page, VisioAutomation.ShapeSheet.CellValueType.Formula); }
public void Render(IVisio.Page page) { if (page == null) { throw new System.ArgumentNullException(nameof(page)); } // First handle any page properties if (this.Name != null) { page.NameU = this.Name; } this.VisioPage = page; var page_sheet = page.PageSheet; var app = page.Application; using (var perfscope = new RenderPerformanceScope(app, this.RenderPerforfmanceSettings)) { if (this.Size.HasValue) { this.PageFormatCells.Height = this.Size.Value.Height; this.PageFormatCells.Width = this.Size.Value.Width; } var writer = new SidSrcWriter(); writer.SetValues((short)page_sheet.ID, this.PageFormatCells); writer.SetValues((short)page_sheet.ID, this.PageLayoutCells); writer.Commit(page, ShapeSheet.CellValueType.Formula); // Then render the shapes this.Shapes.Render(page); // Perform any additional layout if (this.Layout != null) { this.Layout.Apply(page); } // Optionally, perform page resizing to fit contents if (this.ResizeToFit) { if (this.ResizeToFitMargin.HasValue) { page.ResizeToFitContents(this.ResizeToFitMargin.Value); } else { page.ResizeToFitContents(); } } } }
public static void Spirograph() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); page.Name = "Spirograph"; var colors = new[] { 0xf26420, 0xf7931c, 0xfec20d, 0xfff200, 0xcada28, 0x8cc63e, 0x6c9d30, 0x288f39, 0x006f3a, 0x006f71, 0x008eb0, 0x00adee, 0x008ed3, 0x0071bb, 0x0053a6, 0x2e3091, 0x5b57a6, 0x652d91, 0x92278e, 0xbd198c, 0xec008b, 0xec1c23, 0xc1272c, 0x981a1e }; var origin = new VA.Geometry.Point(4, 4); double radius = 3.0; int numpoints = colors.Length; double angle_step = (System.Math.PI * 2 / numpoints); var angles = Enumerable.Range(0, numpoints).Select(i => i * angle_step).ToList(); var centers = angles.Select(a => PlaygroundSamples.GetPointAtRadius(origin, a, radius)).ToList(); var shapes = centers.Select(p => PlaygroundSamples.draw_leaf(page, p)).ToList(); var culture = CultureInfo.InvariantCulture; var angles_as_formulas = angles.Select(a => a.ToString(culture)).ToList(); var color_formulas = colors.Select(x => new VA.Models.Color.ColorRgb(x).ToFormula()).ToList(); var shapeids = shapes.Select(s => s.ID16).ToList(); var writer = new SidSrcWriter(); var format = new VA.Shapes.ShapeFormatCells(); var xfrm = new VA.Shapes.ShapeXFormCells(); foreach (int i in Enumerable.Range(0, shapeids.Count)) { short shapeid = shapeids[i]; xfrm.Angle = angles_as_formulas[i]; format.FillForeground = color_formulas[i]; format.LineWeight = 0; format.LinePattern = 0; format.FillForegroundTransparency = 0.5; writer.SetValues(shapeid, xfrm); writer.SetValues(shapeid, format); } writer.Commit(page, VA.ShapeSheet.CellValueType.Formula); page.ResizeToFitContents(new VA.Geometry.Size(1.0, 1.0)); }
public static void ProgressBar() { var page_a = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Draw some shapes var background = page_a.DrawRectangle(0, 0, 5, 1); var progress = page_a.DrawRectangle(0, 0, 1, 1); var background_fmt = new VA.Shapes.ShapeFormatCells(); background_fmt.FillForeground = "rgb(240,240,240)"; background_fmt.LineColor = "rgb(100,100,100)"; var progress_fmt = new VA.Shapes.ShapeFormatCells(); progress_fmt.FillForeground = "rgb(100,150,240)"; progress_fmt.LineColor = "rgb(100,100,100)"; // group the two shapes together page_a.Application.ActiveWindow.SelectAll(); var group = page_a.Application.ActiveWindow.Selection.Group(); // Set the progress shape update itself based on its position string bkname = background.NameID; var xfrm = new VA.Shapes.ShapeXFormCells(); xfrm.PinX = string.Format("GUARD({0}!PinX-{0}!LocPinX+LocPinX)", bkname); xfrm.PinY = string.Format("GUARD({0}!PinY)", bkname); xfrm.Width = string.Format("GUARD({0}!Width*(PAGENUMBER()/PAGECOUNT()))", bkname); xfrm.Height = string.Format("GUARD({0}!Height)", bkname); var writer = new SidSrcWriter(); xfrm.SetFormulas(writer, progress.ID16); background_fmt.SetFormulas(writer, progress.ID16); progress_fmt.SetFormulas(writer, progress.ID16); writer.Commit(page_a); var markup1 = new VisioAutomation.Models.Text.Element(); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageName); markup1.AddText(" ("); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.PageNumber); markup1.AddText(" of "); markup1.AddField(VisioAutomation.Models.Text.FieldConstants.NumberOfPages); markup1.AddText(") "); markup1.SetText(group); }
public void Finish() { var writer = new SidSrcWriter(); foreach (var block in this.Blocks) { block.FormatCells.SetFormulas((short)block.VisioShapeID, writer); block.TextBlockCells.SetFormulas((short)block.VisioShapeID, writer); block.ParagraphCells.SetFormulas((short)block.VisioShapeID, writer, 0); block.CharacterCells.SetFormulas((short)block.VisioShapeID, writer, 0); } writer.Commit(this._page); }
public void Finish() { var writer = new SidSrcWriter(); foreach (var block in this.Blocks) { writer.SetValues((short)block.VisioShapeID, block.FormatCells); writer.SetValues((short)block.VisioShapeID, block.TextBlockCells); writer.SetValues((short)block.VisioShapeID, block.ParagraphFormatCells, 0); writer.SetValues((short)block.VisioShapeID, block.CharacterFormatCells, 0); } writer.Commit(this._page, ShapeSheet.CellValueType.Formula); }
private void UpdateCells(RenderContext context) { this._update_cells_with_drop_sizes(context); var writer = new SidSrcWriter(); var shapes_with_cells = this._shapes.Where(s => s.Cells != null); foreach (var shape in shapes_with_cells) { var fmt = shape.Cells; short id = shape.VisioShapeID; fmt.Apply(writer, id); } writer.Commit(context.VisioPage, ShapeSheet.CellValueType.Formula); }
private void UpdateCells(RenderContext context) { this.UpdateCellsWithDropSizes(context); var writer = new SidSrcWriter(); var shapes_with_cells = this._shapes.Where(s => s.Cells != null); foreach (var shape in shapes_with_cells) { var fmt = shape.Cells; short id = shape.VisioShapeID; fmt.Apply(writer, id); } writer.Commit(context.VisioPage); }
public static void set_text_wrapping(IVisio.Page page, IList <int> shapeids, bool wrap) { const string formula_wrap = "WIDTH*1"; const string formula_no_wrap = "TEXTWIDTH(TheText)"; string formula = wrap ? formula_wrap : formula_no_wrap; var writer = new SidSrcWriter(); foreach (int shapeid in shapeids) { writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.TextXFormWidth, formula); } writer.Commit(page); }
public void FitShapeToText(VisioScripting.Models.TargetShapes targets) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes2D(this._client); if (shapes.Shapes.Count < 1) { return; } var application = this._client.Application.Get(); var active_page = application.ActivePage; var shapeids = shapes.Shapes.Select(s => s.ID).ToList(); using (var undoscope = this._client.Application.NewUndoScope("Fit Shape To Text")) { // Calculate the new sizes for each shape var new_sizes = new List <VisioAutomation.Drawing.Size>(shapeids.Count); foreach (var shape in shapes.Shapes) { var text_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightText).Size; var wh_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH).Size; double max_w = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width); double max_h = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height); var max_size = new VisioAutomation.Drawing.Size(max_w, max_h); new_sizes.Add(max_size); } var src_width = VisioAutomation.ShapeSheet.SrcConstants.XFormWidth; var src_height = VisioAutomation.ShapeSheet.SrcConstants.XFormHeight; var writer = new SidSrcWriter(); for (int i = 0; i < new_sizes.Count; i++) { var shapeid = shapeids[i]; var new_size = new_sizes[i]; writer.SetFormula((short)shapeid, src_width, new_size.Width); writer.SetFormula((short)shapeid, src_height, new_size.Height); } writer.Commit(active_page); } }
public void PasteFormat(IVisio.Page page, IList <int> shapeids, FormatPaintCategory paint_category, bool applyformulas) { // Find all the cells that are going to be pasted var matching_cells = this.Cells.Where(c => c.MatchesCategory(paint_category)).ToArray(); // Apply those matched cells to each shape var writer = new SidSrcWriter(); foreach (var shape_id in shapeids) { foreach (var cell in matching_cells) { var sidsrc = new VisioAutomation.ShapeSheet.SidSrc((short)shape_id, cell.Src); var new_formula = applyformulas ? cell.Formula : cell.Result; writer.SetFormula(sidsrc, new_formula); } } writer.Commit(page); }
public void ShapeSheet_Writer_Formulas_MultipleShapes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(-1, -1, 0, 0); var shape2 = page1.DrawRectangle(-1, -1, 0, 0); var shape3 = page1.DrawRectangle(-1, -1, 0, 0); // Set the formulas var writer = new SidSrcWriter(); writer.SetFormula(shape1.ID16, XFormPinX, 0.5); writer.SetFormula(shape1.ID16, XFormPinY, 0.5); writer.SetFormula(shape2.ID16, XFormPinX, 1.5); writer.SetFormula(shape2.ID16, XFormPinY, 1.5); writer.SetFormula(shape3.ID16, XFormPinX, 2.5); writer.SetFormula(shape3.ID16, XFormPinY, 2.5); writer.Commit(page1); // Verify that the formulas were set var query = new CellQuery(); var col_pinx = query.Columns.Add(XFormPinX, nameof(XFormPinX)); var col_piny = query.Columns.Add(XFormPinY, nameof(XFormPinY)); var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID }; var data_formulas = query.GetFormulas(page1, shapeids); var data_results = query.GetResults <double>(page1, shapeids); AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0].Cells[col_pinx], data_results[0].Cells[col_pinx])); AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0].Cells[col_piny], data_results[0].Cells[col_piny])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1].Cells[col_pinx], data_results[1].Cells[col_pinx])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1].Cells[col_piny], data_results[1].Cells[col_piny])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2].Cells[col_pinx], data_results[2].Cells[col_pinx])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2].Cells[col_piny], data_results[2].Cells[col_piny])); page1.Delete(0); }
public void ShapeSheet_Writer_ResultsDouble_MultipleShapes() { var page1 = this.GetNewPage(); var shape1 = page1.DrawRectangle(-1, -1, 0, 0); var shape2 = page1.DrawRectangle(-1, -1, 0, 0); var shape3 = page1.DrawRectangle(-1, -1, 0, 0); // Set the formulas var writer = new SidSrcWriter(); writer.SetResult(shape1.ID16, src_pinx, 0.5); writer.SetResult(shape1.ID16, src_piny, 0.5); writer.SetResult(shape2.ID16, src_pinx, 1.5); writer.SetResult(shape2.ID16, src_piny, 1.5); writer.SetResult(shape3.ID16, src_pinx, 2.5); writer.SetResult(shape3.ID16, src_piny, 2.5); writer.Commit(page1); // Verify that the formulas were set var query = new ShapeSheetQuery(); var col_pinx = query.AddCell(ShapeSheetWriterTests.src_pinx, "PinX"); var col_piny = query.AddCell(ShapeSheetWriterTests.src_piny, "PinY"); var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID }; var data_formulas = query.GetFormulas(page1, shapeids); var data_results = query.GetResults <double>(page1, shapeids); AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0].Cells[col_pinx], data_results[0].Cells[col_pinx])); AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0].Cells[col_piny], data_results[0].Cells[col_piny])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1].Cells[col_pinx], data_results[1].Cells[col_pinx])); AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1].Cells[col_piny], data_results[1].Cells[col_piny])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2].Cells[col_pinx], data_results[2].Cells[col_pinx])); AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2].Cells[col_piny], data_results[2].Cells[col_piny])); page1.Delete(0); }
private static short[] DropManyU( IVisio.Page page, IList <IVisio.Master> masters, IList <Drawing.Rectangle> rects) { var points = rects.Select(r => r.Center).ToList(); var shapeids = page.DropManyU(masters, points); // Dropping takes care of the PinX and PinY // Now set the Width's and Heights var writer = new SidSrcWriter(); for (int i = 0; i < rects.Count(); i++) { writer.SetFormula(shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, rects[i].Width); writer.SetFormula(shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, rects[i].Height); } writer.Commit(page); return(shapeids); }
internal void __SetCells(VisioScripting.Models.TargetShapes targets, VisioAutomation.ShapeSheet.CellGroups.CellGroupBase cells, IVisio.Page page) { targets = targets.ResolveShapes(this._client); var shape_ids = targets.ToShapeIDs(); var writer = new SidSrcWriter(); foreach (var shape_id in shape_ids.ShapeIDs) { if (cells is VisioAutomation.ShapeSheet.CellGroups.CellGroupMultiRow) { var cells_mr = (VisioAutomation.ShapeSheet.CellGroups.CellGroupMultiRow)cells; cells_mr.SetFormulas((short)shape_id, writer, 0); } else { var cells_sr = (VisioAutomation.ShapeSheet.CellGroups.CellGroupSingleRow)cells; cells_sr.SetFormulas((short)shape_id, writer); } } writer.Commit(page); }
public void PasteSize(VisioScripting.Models.TargetShapes targets, bool paste_width, bool paste_height) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return; } if ((!this.cached_size_width.HasValue) && (!this.cached_size_height.HasValue)) { return; } var writer = new SidSrcWriter(); var shapeids = targets.Shapes.Select(s => s.ID).ToList(); foreach (var shapeid in shapeids) { if (paste_width) { writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, this.cached_size_width.Value); } if (paste_height) { writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, this.cached_size_height.Value); } } var application = this._client.Application.Get(); var active_page = application.ActivePage; writer.Commit(active_page); }
public void MoveTextToBottom(VisioScripting.Models.TargetShapes targets) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return; } var writer = new SidSrcWriter(); foreach (var shape in targets.Shapes) { if (0 == shape.RowExists[ (short)IVisio.VisSectionIndices.visSectionObject, (short)IVisio.VisRowIndices.visRowTextXForm, (short)IVisio.VisExistsFlags.visExistsAnywhere]) { shape.AddRow((short)IVisio.VisSectionIndices.visSectionObject, (short)IVisio.VisRowIndices.visRowTextXForm, (short)IVisio.VisRowTags.visTagDefault); } } var application = this._client.Application.Get(); var shapeids = targets.Shapes.Select(s => s.ID); foreach (int shapeid in shapeids) { writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.TextXFormHeight, "Height*0"); writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.TextXFormPinY, "Height*0"); writer.SetFormula((short)shapeid, VisioAutomation.ShapeSheet.SrcConstants.TextBlockVerticalAlign, "0"); } writer.Commit(application.ActivePage); }
public void Set(VisioScripting.Models.TargetShapes targets, VisioAutomation.Shapes.ShapeFormatCells format) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return; } var writer = new SidSrcWriter(); var shapeids = targets.Shapes.Select(s => s.ID).ToList(); foreach (int shapeid in shapeids) { format.SetFormulas((short)shapeid, writer); } var application = this._client.Application.Get(); writer.Commit(application.ActivePage); }
public IVisio.Page Render(IVisio.Document doc) { if (!this.IsLayedOut) { string msg = string.Format("{0} usage error. {1}() before calling {2}().", nameof(ContainerLayout), nameof(PerformLayout), nameof(Render)); throw new System.ArgumentException(msg); } // create a new drawing var app = doc.Application; var docs = app.Documents; var pages = doc.Pages; var page = pages.Add(); // load the stencil used to draw the items var item_stencil = docs.OpenStencil(this.LayoutOptions.ManualItemStencil); var item_stencil_masters = item_stencil.Masters; var item_master = item_stencil_masters[this.LayoutOptions.ManualItemMaster]; var plain_container_master = item_stencil_masters[this.LayoutOptions.ManualContainerMaster]; var page_shapes = page.Shapes; // Drop the container shapes var ct_items = this.Containers.ToList(); var ct_rects = ct_items.Select(item => item.Rectangle).ToList(); var masters = ct_items.Select(i => plain_container_master).ToList(); short[] ct_shapeids = ContainerLayout.DropManyU(page, masters, ct_rects); // associate each container with the corresponding shape oject and shape id for (int i = 0; i < ct_items.Count; i++) { var ct_item = ct_items[i]; var ct_shapeid = ct_shapeids[i]; var shape = page_shapes[ct_shapeid]; ct_item.VisioShape = shape; ct_item.ShapeID = ct_shapeid; } // Render the items var items = this.ContainerItems.ToList(); var item_rects = items.Select(item => item.Rectangle).ToList(); var item_masters = items.Select(i => item_master).ToList(); short[] shapeids = ContainerLayout.DropManyU(page, item_masters, item_rects); // Associate each item with the corresponding shape object and shape id for (int i = 0; i < items.Count; i++) { var item = items[i]; var shapeid = shapeids[i]; var shape = page_shapes[shapeid]; item.VisioShape = shape; item.ShapeID = shapeid; } // Often useful to show everthing because these diagrams can get large app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; // Set the items foreach (var item in items.Where(i => i.Text != null)) { item.VisioShape.Text = item.Text; } var writer = new SidSrcWriter(); // Format the containers and shapes foreach (var item in this.Containers) { this.LayoutOptions.ContainerFormatting.Apply(writer, item.ShapeID, item.ShapeID); } foreach (var item in this.ContainerItems) { this.LayoutOptions.ContainerItemFormatting.Apply(writer, item.ShapeID, item.ShapeID); } writer.BlastGuards = true; writer.Commit(page); // Set the Container Text foreach (var ct in this.Containers) { if (ct.Text != null) { ct.Text.SetText(ct.VisioShape); } } page.ResizeToFitContents(); app.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; return(page); }
public static void ColorGrid() { // Draws a grid rectangles and then formats the shapes // with different colors // Demonstrates: // How use the GridLayout object to quickly drop a grid // How to use ShapeFormatCells to apply formatting to shapes // How UpdateBase can be used to modfiy multiple shapes at once int[] colors = { 0x0A3B76, 0x4395D1, 0x99D9EA, 0x0D686B, 0x00A99D, 0x7ACCC8, 0x82CA9C, 0x74A402, 0xC4DF9B, 0xD9D56F, 0xFFF468, 0xFFF799, 0xFFC20E, 0xEB6119, 0xFBAF5D, 0xE57300, 0xC14000, 0xB82832, 0xD85171, 0xFEDFEC, 0x563F7F, 0xA186BE, 0xD9CFE5 }; const int num_cols = 5; const int num_rows = 5; var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var page_size = new VA.Drawing.Size(10, 10); SampleEnvironment.SetPageSize(page, page_size); var stencil = SampleEnvironment.Application.Documents.OpenStencil("basic_u.vss"); var master = stencil.Masters["Rectangle"]; var layout = new GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master); layout.Origin = new VA.Drawing.Point(0, 0); layout.CellSpacing = new VA.Drawing.Size(0, 0); layout.RowDirection = RowDirection.BottomToTop; layout.PerformLayout(); layout.Render(page); var fmtcells = new VA.Shapes.ShapeFormatCells(); int i = 0; var writer = new SidSrcWriter(); foreach (var node in layout.Nodes) { var shapeid = node.ShapeID; int color_index = i % colors.Length; var color = colors[color_index]; fmtcells.FillForeground = new VisioAutomation.Drawing.ColorRgb(color).ToFormula(); fmtcells.LinePattern = 0; fmtcells.LineWeight = 0; fmtcells.SetFormulas(shapeid, writer); i++; } writer.Commit(page); var bordersize = new VA.Drawing.Size(1, 1); page.ResizeToFitContents(bordersize); }
public static void DrawAllGradients() { var app = SampleEnvironment.Application; var docs = app.Documents; var stencil = docs.OpenStencil("basic_u.vss"); var master = stencil.Masters["Rectangle"]; var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); int num_cols = 7; int num_rows = 7; var page_size = new VA.Geometry.Size(5, 5); SampleEnvironment.SetPageSize(page, page_size); var lowerleft = new VA.Geometry.Point(0, 0); var actual_page_size = SampleEnvironment.GetPageSize(page); var page_rect = new VA.Geometry.Rectangle(lowerleft, actual_page_size); var layout = new GridLayout(num_cols, num_rows, new VA.Geometry.Size(1, 1), master); layout.RowDirection = RowDirection.TopToBottom; layout.Origin = page_rect.UpperLeft; layout.CellSpacing = new VA.Geometry.Size(0, 0); layout.PerformLayout(); int max_grad_id = 40; int n = 0; foreach (var node in layout.Nodes) { int grad_id = n % max_grad_id; node.Text = grad_id.ToString(); n++; } layout.Render(page); var color1 = new VA.Models.Color.ColorRgb(0xffdddd); var color2 = new VA.Models.Color.ColorRgb(0x00ffff); var format = new VA.Shapes.ShapeFormatCells(); var writer = new SidSrcWriter(); string color1_formula = color1.ToFormula(); string color2_formula = color2.ToFormula(); n = 0; foreach (var node in layout.Nodes) { short shapeid = node.ShapeID; int grad_id = n % max_grad_id; format.FillPattern = grad_id; format.FillForeground = color1_formula; format.FillBackground = color2_formula; format.LinePattern = 0; format.LineWeight = 0; writer.SetValues(shapeid, format); n++; } writer.Commit(page, VA.ShapeSheet.CellValueType.Formula); var bordersize = new VA.Geometry.Size(1, 1); page.ResizeToFitContents(bordersize); }