Welcome to MSDN Blogs Sign in | Join | Help

VisioAutoExt: Preparing for an new release and new some sample code

This week I'll be releasing a major update to the VisioAutoExt project (v4.0). In preparation for the release I will be documenting the usage of the library via a series of blog posts. This is the first one.

First, what's in the library?

This diagram was automatically drawn (and required no manual modifications) by a new tool in the VisioAutoExt solution called MakeAssemblyPoster.

image

 

A Walkthrough

I'll describe a very simple task: setting the foreground fill of a shape to Red. We'll start with the "normal" way of doing it and then show how the library can be used

 

The original code

using System;
using System.Collections.Generic;
using System.Linq;
using Isotope.Drawing;
using IVisio = Microsoft.Office.Interop.Visio;
using VisioAutomation.Extensions;
using VisioAutomation.Extensions.Helpers;
using VA=VisioAutomation;

namespace CmdLineTest
{
    internal class Program
    {
        [STAThread]
        private static void Main(string[] args)
        {
            var app = new IVisio.ApplicationClass();
            var doc = app.Documents.Add(new Size(4, 4));
            var page = doc.Pages[1];

            var rect = new Rect(1, 1, 3, 3);
            var shape0 = page.DrawRectangle(rect);

            shape0.get_CellsSRC(
                
(short) IVisio.VisSectionIndices.visSectionObject,
                 (short) IVisio.VisRowIndices.visRowFill,
                
(short) IVisio.VisCellIndices.visFillForegnd )
                .FormulaU = "rgb(255,0,0)";

        }
    }
}

 

now using the CellsSRC extension method in VisioAutomation.Extensions

            shape0.CellsSRC( VA.Cells.FillForegnd )
               
.FormulaU = "rgb(255,0,0)";

Using the the SetFormulaU() extension method makes this a little simpler

            shape0.CellsSRC( VA.Cells.FillForegnd )
                .SetFormulaU(  "rgb(255,0,0)"  );

and SetFormulaU() lets us use other types like this ...

shape0.CellsSRC(VA.Cells.FillForegnd)
    .SetFormulaU(  new Isotope.Drawing.ColorRGB24Bit(255,0,0)  );

And there are a predefined set of colors found in VisioAutomation.Colors.SystemColors

            shape0.CellsSRC( VA.Cells.FillForegnd )
                .SetFormulaU(  VA.Colors.SystemColors.Red  );

 

or use System.Drawing.Color

            shape0.CellsSRC( VA.Cells.FillForegnd )
                .SetFormulaU(  System.Drawing.Color.Red  );

or CMYK

            shape0.CellsSRC(VA.Cells.FillForegnd)
                .SetFormulaU(  new Isotope.Drawing.ColorCMYK(0, 0.65, 0.85, 0)  );

 

or HSV

            shape0.CellsSRC(VA.Cells.FillForegnd)
                .SetFormulaU(  new Isotope.Drawing.ColorHSV(1.0,1.0,1.0)  )

or HSL

shape0.CellsSRC(VA.Cells.FillForegnd)
    .SetFormulaU(  new Isotope.Drawing.ColorHSL(1.0,1.0,0.5)  );

or just "cheat" and use the SetFillForegroundColor() method  in the VisioAutomation.Extension.Helpers namespace

shape0.SetFillForegroundColor(  VA.Colors.SystemColors.Red  );

 

NOTE: By now you may have noticed that SetFormulaU() accepts many color types. You might believe that SetFormulaU() contains multiple overloads, one for each color type. In fact it does not. Instead it uses the C# implicit operator with VisioAutiomation.Color class to support multiple color types with only one method.

Published Tuesday, August 05, 2008 9:44 AM by saveenr

Attachment(s): VisioAutomation-(2008-08-05).vsd

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker