Through the Interface: My first F# application for AutoCAD

May 2015

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


« F# - a perfect fit for AutoCAD .NET programming? | Main | DevTV: Introductory recordings on Autodesk APIs »

October 31, 2007

My first F# application for AutoCAD

I couldn't resist... I just had to have a play with this technology, today. :-)

Here are the steps to get your first (very simple) F# application working inside AutoCAD.

First we need to download and install the latest F# distributable from here (at the time of writing this was the July 31 release -

We create a base F# project, selecting the "F# Project" template:


We now add a new item to the project of type "F# Source File" to the project:


The file created contains a lot of boilerplate code that is definitely worth looking at to get a feel for the basics of the F# language.

We now go ahead and replace this with our own F# code (which I created by borrowing liberally from one of the F# samples from CodePlex... I should say - once again - that this is my very first attempt at using F#, so this was intended to be functional rather than elegant :-).

(* Use lightweight F# syntax *)


(* Declare a specific namespace

  and module name


module MyNamespace.MyApplication

(* Import managed assemblies *)

open System

open System.Windows.Forms

open Autodesk.AutoCAD.Runtime

(* Now we declare our command *)


let f () =

  (* Create our form *)

  let frm = new Form()

  frm.Text <- "This is a WinForm"

  frm.Height <- 80

  frm.Width <- 360

  frm.StartPosition <-


  (* Create the contents:

      a Label

      a TextBox

      a Button


  let lb = new Label()

  lb.Text <- "Enter text: "

  lb.Width <- 60

  lb.Left <- 10

  lb.Top <- 12

  let tb = new TextBox()

  tb.Left <- 80

  tb.Top <- 10

  tb.Width <- 200

  (* Define an EventHandler for

    the Click event and attach

    it to the Button


  let mb _ _ =




        "Text typed:"



  let eh = new EventHandler(mb)

  let bt = new Button()

  bt.Text <- "Submit"

  bt.Left <- 290

  bt.Top <- 8

  bt.Width <- 50


  (* Add the controls to our Form *)




  (* Display the Form *)


To get this code to build, we have to add assembly references to AutoCAD's managed assemblies in our project settings, as well as setting the project type to "DLL":


The application should now build, creating "myfirstfsharpapp.dll". We load this in AutoCAD using the standard NETLOAD command, and then execute our TEST command:


When we enter some text and click "Submit", a message box is displayed with the string we entered:


That's it for this first attempt. In future posts I hope to solve more interesting problems with the F# language, but you do, of course, have to start somewhere.


TrackBack URL for this entry:

Listed below are links to weblogs that reference My first F# application for AutoCAD:

» My first F# application for AutoCAD from
You've been kicked (a good thing) - Trackback from [Read More]

blog comments powered by Disqus


10 Random Posts