Welcome to MSDN Blogs Sign in | Join | Help

Visio and F# interop: a more complex example

In July 2007, I provided a very simple example showing how F# could be used to automate Visio. As my VisioAutoExt project on CodePlex slowly evolves, I learned enough about Visio that I wanted to revisit the F# interop scenario and do something more substantial.

Using the F# version F# 1.9.2.9 (available here). Underneath is the output of the sample code.

image

The source

The full source code is attached.

open visioautoext


let visapp = IVisio.ApplicationClass()
let doc = visapp.Documents.CreateNewDoc()
let page = doc.GetFirstPage()
let r1 = page.GetRect()
//do printf "%O" r1
let s1= page.DrawRectangle( r1 )
do s1.SetFillGradient( 36, System.Drawing.Color.Tomato , System.Drawing.Color.AliceBlue, 50, 20);;
do s1.SetLineRounding(0.0)

let s2= page.DrawRectangle( (0.0, 0.0) , (r1.Right , 1.0) )
do s2.SetLineWidth( 10.0 )
do s2.SetLinePattern( 3 )
do s2.SetLineColor( System.Drawing.Color.Tomato )
do s2.SetFillGradient( 36, System.Drawing.Color.Tomato , System.Drawing.Color.BurlyWood )
//do s1.SetFillForegroundColor( System.Drawing.Color.AntiqueWhite )
//do s1.SetFillBackgroundColor( System.Drawing.Color.AliceBlue )
//do s1.SetFillGradient(36)
//do s1.SetFillGradient( 36, System.Drawing.Color.Tomato , System.Drawing.Color.BurlyWood )

let s3 = page.DrawLine( r1.LowerLeft , r1.CenterPoint)
let s4 = page.DrawLine( r1.CenterPoint, r1.LowerRight )
do s4.SetLineColor( System.Drawing.Color.Azure )
do s3.SetLineWidth( 30.0 )
do s4.SetLineWidth( 20.0 )
let s5 =page.DrawPolyline( drawing.create_random_points_in_rect( 10 , r1 ) )

 

The sample doesn't reuse VisioAutoExt

The F# code does NOT re-use the VisioAutoExt .NET Library. Instead, it re-implements  key pieces from VisioAutoExt and my Isotope.Drawing library.

Why re-implement?

1 - I didn't want to mask any interop difficulties by re-using my a library. Instead, the point was to expose and solve them directly in the F# code.

2 - Where possible I wanted to take advantage of features found in F#.

 

With regard to #2, I'm not fully exploiting what F# offers. As my knowledge and comfort with F# grow, this sample may look very different.

Published Tuesday, January 15, 2008 8:10 AM by saveenr

Attachment(s): visioautoext_fsharp.zip

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