A Simple Message Command

Last time, we have introduced the basic structure of an external Revit command. To test it, let’s complete it by writing a simple “Hello World!” command (just like every other beginner’s first code is supposed to be), which, when executed, will return a message by using Revit’s built-in UI-command “TaskDialog“.

[<TransactionAttribute(TransactionMode.Manual)>]
type ASimpleMessage() =
  interface IExternalCommand with
  member this.Execute(cdata, msg, elset) =
    TaskDialog.Show("Title", "Hello World!") |> ignore
  Result.Succeeded

Surely, don’t forget to declare the namespace of this library at the beginning of the F# source file(.fs).

namespace TYB.Tutorial.Wordpress

And also the modules of Revit which we use here – by default if you use Microsoft Visual Studio for coding, it will suggest you which of the reference that has been used in your code, and put it into the correct position for you. (See the post regarding setting coding environment)

open Autodesk.Revit.Attributes
open Autodesk.Revit.UI

An external command is just as simple as this is! The code, which you want to tell Revit to do just like what you want, comes right into line number 5, between the “member” definition until the final “Result” output. In this case we have a simple call for a “TaskDialog” from Revit’s UI namespace and a dialog window will pop-up when you hit the command button.

This is a simple introduction of the common coding structure (what we want to do comes in the line #5) for an external command in Revit. To complete compiling the command as a dynamic-link library file (.dll), Microsoft Visual Studio comes in handy. However, before getting into the compilation of a code, let’s take a look at the add-in file for loading an external command – the .dll file – into Revit environment.

More is to come…

Published by

Ching-Hua Chen / 陳景華

The logic behind coding structures will be unveiled during step by step practices. A strong background from computer science is not what I have. I’m just an enthusiast of programming, especially in fields of geometry and architecture. Currently I work for an office in Vienna on a BIM project and I write codes in F# and Python, if needed, for the project, but mostly for my own interest.

3 thoughts on “A Simple Message Command”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.