public static VisioAutomation.Models.Text.Element AddElementEx(this VisioAutomation.Models.Text.Element p, string text, int?font, double?size, int?color, VisioScripting.Models.AlignmentHorizontal?halign, VA.Models.Text.CharStyle?cs) { var el = p.AddElement(text); if (font != null) { el.CharacterFormatting.Font = font.Value; } if (size.HasValue) { el.CharacterFormatting.Size = string.Format("{0}pt", size.Value); } if (color.HasValue) { var c = new VisioAutomation.Drawing.ColorRgb(color.Value); el.CharacterFormatting.Color = c.ToFormula(); } if (halign.HasValue) { el.ParagraphFormatting.HorizontalAlign = (int)halign.Value; } if (cs.HasValue) { el.CharacterFormatting.Style = (int)cs; } return(el); }
public static void GradientTransparencies() { int num_cols = 1; int num_rows = 10; var color1 = new VisioAutomation.Drawing.ColorRgb(0xff000); var color2 = new VisioAutomation.Drawing.ColorRgb(0x000ff); var page_size = new VA.Drawing.Size(num_rows / 2.0, num_rows); var upperleft = new VA.Drawing.Point(0, page_size.Height); var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); var app = page.Application; var docs = app.Documents; var stencil = docs.OpenStencil("basic_U.vss"); var master = stencil.Masters["Rectangle"]; SampleEnvironment.SetPageSize(page, page_size); var layout = new GridLayout(num_cols, num_rows, new VA.Drawing.Size(6.0, 1.0), master); layout.RowDirection = RowDirection.TopToBottom; layout.Origin = upperleft; layout.CellSpacing = new VA.Drawing.Size(0.1, 0.1); layout.PerformLayout(); double[] trans = EffectsSamples.RangeSteps(0.0, 1.0, num_rows).ToArray(); int i = 0; foreach (var node in layout.Nodes) { double transparency = trans[i]; var fmt = new ShapeCells(); node.Cells = fmt; fmt.FillPattern = 25; // Linear pattern left to right fmt.FillForeground = color1.ToFormula(); fmt.FillBackground = color2.ToFormula(); fmt.FillForegroundTransparency = 0; fmt.FillBackgroundTransparency = transparency; fmt.LinePattern = 0; node.Text = string.Format("bg trans = {0}%", transparency); i++; } layout.Render(page); page.ResizeToFitContents(); }
public static void TextMarkup11() { var page = SampleEnvironment.Application.ActiveDocument.Pages.Add(); // Create the Shapes that will hold the text var s1 = page.DrawRectangle(0, 0, 8.5, 11); var tnr = page.Document.Fonts["Times New Roman"]; var e1 = new VisioAutomation.Models.Text.Element(); var color_red = new VisioAutomation.Drawing.ColorRgb(0xff0000); e1.CharacterFormatting.Color = color_red.ToFormula(); e1.CharacterFormatting.Font = tnr.ID; e1.CharacterFormatting.Font = "20pt"; e1.AddText("Hello World"); e1.SetText(s1); }
public static VisioAutomation.Drawing.ColorRgb AttributeAsColor(this SXL.XElement el, string name, VisioAutomation.Drawing.ColorRgb def) { return(el.GetAttributeValue(name, def, VisioAutomation.Drawing.ColorRgb.ParseWebColor)); }
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.Drawing.Size(5, 5); SampleEnvironment.SetPageSize(page, page_size); var lowerleft = new VA.Drawing.Point(0, 0); var actual_page_size = SampleEnvironment.GetPageSize(page); var page_rect = new VA.Drawing.Rectangle(lowerleft, actual_page_size); var layout = new GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master); layout.RowDirection = RowDirection.TopToBottom; layout.Origin = page_rect.UpperLeft; layout.CellSpacing = new VA.Drawing.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.Drawing.ColorRgb(0xffdddd); var color2 = new VA.Drawing.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; format.SetFormulas(shapeid, writer); n++; } writer.Commit(page); var bordersize = new VA.Drawing.Size(1, 1); page.ResizeToFitContents(bordersize); }
public static List <DirectedGraphLayout> LoadFromXML(Client client, SXL.XDocument xmldoc) { var pagedatas = DirectedGraphBuilder.LoadPageDataFromXML(client, xmldoc); // STOP IF ANY ERRORS int num_errors = pagedatas.Select(pagedata => pagedata.Errors.Count).Sum(); if (num_errors > 1) { foreach (var pagedata in pagedatas) { foreach (var error in pagedata.Errors) { client.WriteVerbose(error.Text); } client.WriteVerbose("Errors encountered in shape data. Stopping."); } } // DRAW EACH PAGE foreach (var pagedata in pagedatas) { client.WriteVerbose("Creating shape AutoLayout nodes"); foreach (var shape_info in pagedata.ShapeInfos) { var dg_shape = pagedata.DirectedGraph.AddShape(shape_info.ID, shape_info.Label, shape_info.Stencil, shape_info.Master); dg_shape.URL = shape_info.URL; dg_shape.CustomProperties = new CustomPropertyDictionary(); foreach (var kv in shape_info.custprops) { dg_shape.CustomProperties[kv.Key] = kv.Value; } } client.WriteVerbose("Creating connector AutoLayout nodes"); foreach (var con_info in pagedata.ConnectorInfos) { var def_connector_type = ConnectorType.Curved; var connectory_type = def_connector_type; var from_shape = pagedata.DirectedGraph.Shapes.Find(con_info.From); var to_shape = pagedata.DirectedGraph.Shapes.Find(con_info.To); var def_con_color = new VisioAutomation.Drawing.ColorRgb(0x000000); var def_con_weight = 1.0 / 72.0; var def_end_arrow = 2; var dg_connector = pagedata.DirectedGraph.AddConnection(con_info.ID, from_shape, to_shape, con_info.Label, connectory_type); dg_connector.Cells = new ShapeCells(); dg_connector.Cells.LineColor = con_info.Element.AttributeAsColor("color", def_con_color).ToFormula(); dg_connector.Cells.LineWeight = con_info.Element.AttributeAsInches("weight", def_con_weight); dg_connector.Cells.LineEndArrow = def_end_arrow; } client.WriteVerbose("Rendering AutoLayout..."); } client.WriteVerbose("Finished rendering AutoLayout"); var directedgraphs = pagedatas.Select(pagedata => pagedata.DirectedGraph).ToList(); return(directedgraphs); }