December 2014

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      










« Implementing your own AutoCAD color combobox control using .NET | Main | Embedding AutoCAD 2009 in a standalone dialog »

March 25, 2008

Initialization code in your F# AutoCAD application

Back from a nice long weekend, although I spent most of it sick with a cold. I find this increasingly the way with me: I fend off illness for months at a time (probably through stress, truth be told) but then I get a few days off and wham. A shame, as we had a huge dump of snow over the weekend... we get white Christmases here every five years or so, but it's really uncommon to get a white Easter.

I had a very interesting question come in by email from 冷血儿, who wanted to get the technique shown in this post working in his F# application.

Here's the F# code I managed to put together after consulting hubFS, in particular:

#light


namespace MyNamespace


open Autodesk.AutoCAD.Runtime

open Autodesk.AutoCAD.ApplicationServices


type InitTest() =

  class

    let ed =

      Application.DocumentManager.MdiActiveDocument.Editor

    interface IExtensionApplication with

      member x.Initialize() =

        ed.WriteMessage

          ("\nInitializing - do something useful.")

      member x.Terminate() =

        printfn "\nCleaning up..."

  end

end


module MyApplication =

  let ed =

    Application.DocumentManager.MdiActiveDocument.Editor

  [<CommandMethod("TST")>]

  let f () =

    ed.WriteMessage("\nThis is the TST command.")

  [<assembly: ExtensionApplication(type InitTest)>]

  do

    ed.WriteMessage("\nModule do")

Here's what happens when we load our module and run the TST command:

Command: NETLOAD

Module do

Initializing - do something useful.

Command: TST

This is the TST command.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200e551711a2c8833

Listed below are links to weblogs that reference Initialization code in your F# AutoCAD application:

» F# and ArcGIS/ArcObjects from Don Syme's WebLog on F# and Other Research Projects
Ray Vernagus has posted an introduction to using F# with ArcGIS through ArcObjects . One of the things [Read More]

blog comments powered by Disqus

Feed/Share

10 Random Posts