public static VA.Text.Markup.TextElement AddElementEx(this VA.Text.Markup.TextElement p, string text, int? font, double? size, int? color, VA.Drawing.AlignmentHorizontal? halign, VA.Text.CharStyle? cs) { var el = p.AddElement(text); if (font != null) { el.CharacterCells.Font = font.Value; } if (size.HasValue) { el.CharacterCells.Size = string.Format("{0}pt",size.Value); } if (color.HasValue) { var c = new VA.Drawing.ColorRGB(color.Value); el.CharacterCells.Color = c.ToFormula(); } if (halign.HasValue) { el.ParagraphCells.HorizontalAlign = (int) halign.Value; } if (cs.HasValue) { el.CharacterCells.Style = (int) cs; } return el; }
public static VisioAutomation.Models.Text.Element AddElementEx(this VisioAutomation.Models.Text.Element p, string text, int?font, double?size, int?color, VisioAutomation.Scripting.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 VA.Text.Markup.TextElement AddElementEx(this VA.Text.Markup.TextElement p, string text, int?font, double?size, int?color, VA.Drawing.AlignmentHorizontal?halign, VA.Text.CharStyle?cs) { var el = p.AddElement(text); if (font != null) { el.CharacterCells.Font = font.Value; } if (size.HasValue) { el.CharacterCells.Size = string.Format("{0}pt", size.Value); } if (color.HasValue) { var c = new VA.Drawing.ColorRGB(color.Value); el.CharacterCells.Color = c.ToFormula(); } if (halign.HasValue) { el.ParagraphCells.HorizontalAlign = (int)halign.Value; } if (cs.HasValue) { el.CharacterCells.Style = (int)cs; } return(el); }
public static IList<DGMODEL.Drawing> LoadFromXML(VA.Scripting.Client client, SXL.XDocument xmldoc) { var pagedatas = 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 Dictionary<string, VACUSTPROP.CustomPropertyCells>(); 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 = VACXN.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 VA.Drawing.ColorRGB(0x000000); var def_con_weight = 1.0/72.0; var def_end_arrow = 2; var dg_connector = pagedata.DirectedGraph.Connect(con_info.ID, from_shape, to_shape, con_info.Label, connectory_type); dg_connector.Cells = new VA.DOM.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.EndArrow = def_end_arrow; } client.WriteVerbose( "Rendering AutoLayout..."); } client.WriteVerbose( "Finished rendering AutoLayout"); var directedgraphs = pagedatas.Select(pagedata => pagedata.DirectedGraph).ToList(); return directedgraphs; }
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 GradientTransparencies() { int num_cols = 1; int num_rows = 10; var color1 = new VA.Drawing.ColorRGB(0xff000); var color2 = new VA.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 GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(6.0, 1.0), master); layout.RowDirection = GRIDMODEL.RowDirection.TopToBottom; layout.Origin = upperleft; layout.CellSpacing = new VA.Drawing.Size(0.1, 0.1); layout.PerformLayout(); double[] trans = RangeSteps(0.0, 1.0, num_rows).ToArray(); int i = 0; foreach (var node in layout.Nodes) { double transparency = trans[i]; var fmt = new VA.DOM.ShapeCells(); node.Cells = fmt; fmt.FillPattern = 25; // Linear pattern left to right fmt.FillForegnd = color1.ToFormula(); fmt.FillBkgnd = color2.ToFormula(); fmt.FillForegndTrans = 0; fmt.FillBkgndTrans = 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 VA.Text.Markup.TextElement(); var color_red = new VA.Drawing.ColorRGB(0xff0000); e1.CharacterCells.Color = color_red.ToFormula(); e1.CharacterCells.Font = tnr.ID; e1.CharacterCells.Font = "20pt"; e1.AddText("Hello World"); e1.SetText(s1); }
public static void TextMarkup12() { 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 "); var e2 = e1.AddElementEx("World", null, null, null, null, VA.Models.Text.CharStyle.Italic); e1.SetText(s1); }
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 VisioAutomation.Shapes.CustomProperties.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); }
public static VA.Drawing.ColorRGB AttributeAsColor(this SXL.XElement el, string name, VA.Drawing.ColorRGB def) { return(VA.Scripting.XmlUtil.GetAttributeValue(el, name, def, VA.Drawing.ColorRGB.ParseWebColor)); }
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)); }
private static void draw_colors(List<System.Drawing.Color> colors) { if (colors.Count < 1) { return; } var app = Globals.ThisAddIn.Application; var domdoc = new VA.DOM.Document(); var page_node = new VA.DOM.Page(); domdoc.Pages.Add(page_node); double y = 8; double col0_w = 3.0; double col0_x = 0; double sep = 0.5; double col1_x = col0_x + col0_w + sep; double cellwidth = 1.0; double col2_x = col1_x + cellwidth + sep; double col3_x = col2_x + cellwidth + sep; var sb = new StringBuilder(); foreach (var color in colors) { var shape0 = page_node.Shapes.DrawRectangle(col0_x, y, col0_x + col0_w, y + cellwidth); var shape1 = page_node.Shapes.DrawRectangle(col1_x, y, col1_x + cellwidth, y + cellwidth); var shape2 = page_node.Shapes.DrawRectangle(col2_x, y, col2_x + cellwidth, y + cellwidth); var shape3 = page_node.Shapes.DrawRectangle(col3_x, y, col3_x + cellwidth, y + cellwidth); var fill = new VisioAutomation.Drawing.ColorRGB(color.R, color.G, color.B); string color_formula = fill.ToFormula(); double trans = (color.A / 255.0); string transparency_formula = trans.ToString(System.Globalization.CultureInfo.InvariantCulture); shape1.Cells.FillForegnd = color_formula; shape1.Cells.LinePattern = "0"; shape1.Cells.LineWeight = "0"; shape2.Cells.LineColor = color_formula; shape2.Cells.LineWeight = "0.25in"; shape2.Cells.FillPattern = "0"; shape3.Cells.CharColor = color_formula; shape3.Cells.FillPattern = "0"; shape3.Cells.LinePattern = "0"; shape3.Cells.LineWeight = "0"; shape3.Text = new VA.Text.Markup.TextElement("ABC"); shape3.CharFontName = "Segoe UI"; shape3.Cells.CharSize = "24pt"; sb.Clear(); sb.AppendFormat("rgb({0},{1},{2})\n", color.R, color.G, color.B); sb.AppendFormat("{0}\n", System.Drawing.ColorTranslator.ToHtml(color)); if (color.A != 255) { sb.AppendFormat("transparency={0:0.00}", trans); } shape0.Text = new VA.Text.Markup.TextElement(sb.ToString()); shape0.CharFontName = "Segoe UI"; shape0.Cells.ParaHorizontalAlign = "0"; shape0.Cells.VerticalAlign = "0"; shape0.Cells.LinePattern = "0"; shape0.Cells.LineWeight = "0"; shape0.Cells.FillForegnd = "rgb(240,240,240)"; if (color.A != 255) { shape1.Cells.FillForegndTrans = transparency_formula; shape2.Cells.LineColorTrans = transparency_formula; shape3.Cells.CharTransparency = transparency_formula; } y -= cellwidth + sep; } page_node.ResizeToFit = true; page_node.ResizeToFitMargin = new VA.Drawing.Size(cellwidth, cellwidth); domdoc.Render(app); var window = app.ActiveWindow; window.ShowPageBreaks = 0; window.ShowGuides = 0; window.DeselectAll(); }
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 GRIDMODEL.GridLayout(num_cols, num_rows, new VA.Drawing.Size(1, 1), master); layout.RowDirection = GRIDMODEL.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.FormatCells(); var update = new VA.ShapeSheet.Update(); 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.FillForegnd = color1_formula; format.FillBkgnd = color2_formula; format.LinePattern = 0; format.LineWeight = 0; update.SetFormulas(shapeid, format); n++; } update.Execute(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.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); }
private static void draw_colors(List <System.Drawing.Color> colors) { if (colors.Count < 1) { return; } var app = Globals.ThisAddIn.Application; var domdoc = new VA.DOM.Document(); var page_node = new VA.DOM.Page(); domdoc.Pages.Add(page_node); double y = 8; double col0_w = 3.0; double col0_x = 0; double sep = 0.5; double col1_x = col0_x + col0_w + sep; double cellwidth = 1.0; double col2_x = col1_x + cellwidth + sep; double col3_x = col2_x + cellwidth + sep; var sb = new StringBuilder(); foreach (var color in colors) { var shape0 = page_node.Shapes.DrawRectangle(col0_x, y, col0_x + col0_w, y + cellwidth); var shape1 = page_node.Shapes.DrawRectangle(col1_x, y, col1_x + cellwidth, y + cellwidth); var shape2 = page_node.Shapes.DrawRectangle(col2_x, y, col2_x + cellwidth, y + cellwidth); var shape3 = page_node.Shapes.DrawRectangle(col3_x, y, col3_x + cellwidth, y + cellwidth); var fill = new VisioAutomation.Drawing.ColorRGB(color.R, color.G, color.B); string color_formula = fill.ToFormula(); double trans = (color.A / 255.0); string transparency_formula = trans.ToString(System.Globalization.CultureInfo.InvariantCulture); shape1.Cells.FillForegnd = color_formula; shape1.Cells.LinePattern = "0"; shape1.Cells.LineWeight = "0"; shape2.Cells.LineColor = color_formula; shape2.Cells.LineWeight = "0.25in"; shape2.Cells.FillPattern = "0"; shape3.Cells.CharColor = color_formula; shape3.Cells.FillPattern = "0"; shape3.Cells.LinePattern = "0"; shape3.Cells.LineWeight = "0"; shape3.Text = new VA.Text.Markup.TextElement("ABC"); shape3.CharFontName = "Segoe UI"; shape3.Cells.CharSize = "24pt"; sb.Clear(); sb.AppendFormat("rgb({0},{1},{2})\n", color.R, color.G, color.B); sb.AppendFormat("{0}\n", System.Drawing.ColorTranslator.ToHtml(color)); if (color.A != 255) { sb.AppendFormat("transparency={0:0.00}", trans); } shape0.Text = new VA.Text.Markup.TextElement(sb.ToString()); shape0.CharFontName = "Segoe UI"; shape0.Cells.ParaHorizontalAlign = "0"; shape0.Cells.VerticalAlign = "0"; shape0.Cells.LinePattern = "0"; shape0.Cells.LineWeight = "0"; shape0.Cells.FillForegnd = "rgb(240,240,240)"; if (color.A != 255) { shape1.Cells.FillForegndTrans = transparency_formula; shape2.Cells.LineColorTrans = transparency_formula; shape3.Cells.CharTransparency = transparency_formula; } y -= cellwidth + sep; } page_node.ResizeToFit = true; page_node.ResizeToFitMargin = new VA.Drawing.Size(cellwidth, cellwidth); domdoc.Render(app); var window = app.ActiveWindow; window.ShowPageBreaks = 0; window.ShowGuides = 0; window.DeselectAll(); }