Discussing Techniques and Programming Languages ​​in Revit Plugin Creation

Revit “Programming Techniques”

In our previous discussion on the Revit API, we reviewed the concept of using the Revit API to craft a plugin to extend the out-of-the-box functionality within Revit. Conceptually speaking, the Revit API is a library of definitions and protocols that can be interacted with through a programming operation to create a capability within Revit. Once one understands the basic premise of creating a Revit plugin, the logical next step is to consider the methods available to undertake the actual “programming” of the plugin.

Traditionally, programming has been the domain of people with extensive knowledge of software development languages. For someone without that background, desired information may be scarce and hard to find, appear overwhelming due to the sheer volume of content available and/or can be difficult to access and understand once found. 

However, as use of applications and computer programs for work and leisure activity has grown and continues to grow exponentially, application users are similarly increasing in number and, more importantly, increasing in knowledge. This increasing knowledge and comfort with technology often leads to “everyday users”, those without deep programming backgrounds, originating wonderful ideas for new software or improvements to existing software. These users are often comfortable enough with technology to “give it a try”. This growth in incidence of technology in everyday life coupled with an ever-more adventurous, idea filled, technologically savvy user populace then naturally leads application developers to continue to evolve their offerings as well.

Coinciding with this, the actual programming systems behind these applications are also evolving. Many applications that support programming through an Application Programming Interface (API), are also incorporating visual programming - a method allowing users to create tools and programs by working with program components graphically as opposed to building them in a traditional text-based coding methodology. Visual programming is a method meant to allow users to attempt to bring an idea to fruition without relying on a traditional programming language. Autodesk and Revit are no strangers to this trend and, in recent versions of Revit, they are incorporating this concept of visual programming. Specifically, Dynamo represents the visual programming technique most often used to build for these applications with their APIs.

This advent of visual programming, appearing as a simpler method for development, may lead to the assumption that it is not necessary to know how to program in the traditional sense, and in a certain way it is true. We don't necessarily need to know how to directly write code to accomplish our goal but we do need to know the API for the tool, such as Revit, that we are working with and we must be aware of both the benefits and limitations inherent in visual programming.

With this baseline of understanding we see that there are two primary programming techniques to interact with the Revit API in order to build capabilities for Revit:

  1. Visual programming (using Dynamo):
    Dynamo in the Revit realm is a plugin in itself that allows the user to access the Revit API. At a high level, the user interacts with a series of nodes that are manipulated, positioned and connected in a “canvas”. Each node roughly corresponds to some functionality of the API, which must be connected by threads with other nodes to build a flow of functionality.

While representing a more accessible method to develop capabilities, there are notable concerns:

  • The size of the screen and drawing area is limited, and although it is possible to create plugins with Dynamo of a larger scope, it can be problematic to trace the functionality across a script/graph that traverses much more than a few “screens”.
  • Dynamo’s capabilities and impact are more limited than operating with a more powerful development platform such as a traditional development in C#. As such, one could find that they need to find another way to implement certain features (nodes) into their Dynamo script.

Dynamo can actually be supplemented through the use of code written in various languages. A developer can create a capability in a traditional programming language and incorporate it into a Dynamo process as a node. This, however, contradicts one of the primary conceptual benefits of Dynamo - the ability to build functionality without needing to have programming knowledge.

In our experience, using Dynamo to extend the capabilities of a package like Revit can work very well for smaller or limited complexity automations, but from there it gets complicated.

  1. “Traditional” programming writing code and compiling it:

Since its inception Revit has exposed its API to the public allowing developers to create plugins to enhance and extend Revit’s capabilities.

The primary methods to “program by code” in Revit include:

  • The use of Macros such as in Microsoft Excel. Traditionally macros have been used to solve smaller, granular needs. The use of macros today is minimal and has been primarily superseded by the use of Dynamo.
  • Programming in a traditional development language to craft plug-ins. This method is essential for large-scale developments, either because of size/volume of features or due to complexity of functionality. Additionally, operations of well-written code will typically out-perform the same operation executed via Dynamo, making traditional code the advisable method when processing speed is a critical factor.
    Traditionally built plugins in Revit are integrated into the Revit environment, appearing as a feature within Revit itself. These are compiled tools operating directly within the Revit environment. However, with Dynamo the plugin is actually processed by the core of Dynamo which recompiles the created script in each execution. Essentially, Dynamo usage adds another layer of processing and resource consumption which can lead to lesser processing speed.

Programming languages ​​in the Revit API.

Revit plugins are normally written in the .NET platform, with plugins created in any of the languages ​​supported by .NET also supported by Revit. The most frequently used .NET languages in use for crafting Revit plugins, all of them being object-oriented languages, are: 

  • ​​Visual Basic .NET (VB.NET) is an object-oriented programming language that can be considered an evolution of Visual Basic implemented within the .NET framework. Its introduction was considered controversial by some since, due to significant changes in the underlying language, VB.NET is not backward compatible with Visual Basic. While not exactly the same, the handling of the instructions is similar to previous versions of Visual Basic but the changes facilitate the development of more advanced applications based on the more modern capabilities of VB.NET.
    The usage of VB.NET in industry, however, has lessened in favor of even more modern, advanced and capable languages such as C# .NET.
  • C# .NET (C Sharp) is a multi-paradigm programming language developed and standardized within the Microsoft .NET framework. Within the framework there is essentially a virtual machine component known as Common Language Runtime (CLR) that actually executes the code of any programs crafted on the .NET framework - with C# .NET being one of the languages understood and executable within the CLR.

The basic syntax of C# .NET derives from C/C++ but operates on the .NET framework and includes improvements and capabilities derived from other languages. The many innovations of C# .NET allows you to develop applications quickly while maintaining the expressiveness and elegance of C.

The name C# (C Sharp) was actually inspired by the ♯ sign in musical notation. It is a play on words since, musically speaking, the symbol # indicates that a note, in this case C, must be a semitone higher. This is a metaphor for the higher capability or superiority of C# over its predecessor C++ which used the ++ symbols to allude to its superiority over C. Furthermore, the # symbol can be imagined as the union of four + symbols, continuing the sense of progression of the C languages.

Unlike Dynamo but similar to VB.NET, C# is a language where written code must be “compiled”. The C# compiler compiles the C# source code into Microsoft Intermediate Language (MSIL) with that code recompiled to the native format on the machine and Operating System it will run on. We can think of this as a two-step build with the output being an executable program that can then be incorporated into the Revit environment.

  • C++ is an object-oriented programming language based on the original C programming language. Today C++ is a versatile, powerful and widely known language. Its success among professional programmers has led it to occupy a top tier as an application development platform. The advantages of C++ over C include greater richness of operators and expressions, flexibility, conciseness and efficiency. It has addressed many of the difficulties and limitations of the C programming language.

In our experience the best option for programming plugins for Revit is currently C#. This opinion is based on several factors:

  • C# is a more future-safe selection. It is a modern language with a large volume of “road mileage”, an excellent track record, deep capability, and enjoys great support throughout the development community. It also has the support and endorsement of Microsoft.
  • It is a fairly easy language to learn, especially for programmers with backgrounds in another C-based language.
  • Most of the examples, help and queries (and answers) you can find about Revit plugins are written in C#.
  • It's a strongly typed language, which is especially helpful when working in the Visual Studio development environment.

While C# is generally our favored plugin development approach, one potential scenario in which we may recommend C++ over C# would be when your application executes a significant volume of calculations. In this case it may be beneficial to use C++ as its speed of operation in calculation-intensive functions may sometimes be superior to C#. 

Regardless of the above considerations, the best choice of one methodology or language over another is the one with which you are most comfortable or familiar. The options to build functionalities are many, with a widely varying degree of prerequisite knowledge. The true benefit of having these choices available is the existence of the ability to incorporate new capabilities and to enhance or extend features of a tool like Revit.

Voyansi’s software team offers services to build Revit plugins to your specification in any of the technologies discussed. Additionally, Voyansi offers training on Dynamo for the user who wishes to try their hand at building features themselves. Contact us to discuss your ideas and needs!