Udostępnij za pośrednictwem


Automating the Timeline Shapes: How many inches are in November?

Like many of the out-of-the-box shapes in Microsoft Office Visio 2003, the Timeline shapes are quite snazzy. No wonder people like to use the “Import Timeline Data…” feature (under the Timeline menu) to display major milestones from a Microsoft Project plan file. “But what about Project Server data,” you might ask? Well, leave it to us developers to provide the extra functionality.

To do this, you are probably going to do some initial research first on how to make Project Data Service (PDS) calls. You’ll need to retrieve data such as project begin-and-end dates, milestones, and tasks. Then, you are going to need to roll-up your sleeves and automate Visio. There are a couple of stumbling blocks I wanted to point out when automating the Visio 2003 Timeline shapes. They have to do with suppressing dialogs and setting date information.

When you drag-and-drop timeline or milestone shapes from the stencil, you get a friendly dialog that lets you enter in things like time periods and milestone dates. Since you’re going to be automating these shapes based on Project Server data, you don’t need the friendly dialogs to display. To suppress them, simply use the AlertResponse property:

// Suppress Visio dialogs. AlertResponse property values

// correspond to the standard Windows constants IDOK (1),

// IDCANCEL (2), and so forth. Set it back to 0, when you

// want Visio dialogs to display again.

vsoApplication.AlertResponse = 1;

Next you’re going to need to set the timeline’s begin-and-end dates. No problem. They are stored in the user-defined cells, as you might expect. Open the timeline’s ShapeSheet and find the User.visBeginDate and User.visEndDate rows of the User-defined Cells section. Upon inspection of the Value cell, you might be perplexed to see something like, 38303. No, it’s not converted to Star Date (yeah, I’m a trekkie). It’s actually stored in Visio internal units, which are inches. Here’s how you set the date in internal units:

// Convert a date value to Internal Units (inches).

beginDateCell.ResultIU =

      visioApplication.ConvertResult("11/11/2004",

      VisUnitCodes.visDate, VisUnitCodes.visInches);

To convert the result back into a readable date:

string strVal =

      beginDateCell.get_ResultStr(VisUnitCodes.visDate);

Automating the milestone shapes should be a piece of a cake now. Simply drop them right on top of the timeline shape. Then, set the User.visMilestoneDate cell using internal units. The milestone shape will automatically move to the correct position on the timeline shape. (Tip: Try using milestones in your Visio solution as you would a standard slider control in a WinForm app.)

I really like the Timeline shapes. They are a great way to show high level Project data. Don’t get me wrong, I like Project’s Gantt charts too, but Visio can provide different visualization options.

-Chris

This posting is provided "AS IS" with no warranties, and confers no rights.