Google Analytics (Hidden)

Monday, April 18, 2011

My first API part 4

Setting up the coding file Class1.cs

The actual coding of your Addin will be taking place in separate *.cs files. In the default template Class1.cs is already predefined. Class1.cs file can contain all code for a complete piece of software. This is probably best if you have a simple piece of software, but in more complex solutions this will become very confusing. In this case, you can create multiple *.cs files for different parts of the software.

So, start with renaming the default Class1.cs to a more suitable name, in this case I renamed it to TestClass.cs. I am told to always use the naming format DescriptionClass, so you can later see that it’s a Class file. Apparently there are also other types of cs-files, but I haven’t come across them just yet… (except off course the AssemblyInfo.cs, but this is in a different section of the Solution Explorer).

After this there are some other default settings that have to be applied.
The first four lines state which parts or containers of the .NET is going to be used. Default parts are the standard system containers. Since we are creating a Addin for Revit, we will also be using containers from the Revit API.

So, place the cursor after the fourth line, hit enter a few times to free up some space and start typing:
using Autodesk.Revit.UI (this allows you to access Revit commands such as move, etc)
using Autodesk.Revit.DB (this allows you to access the Revit Database)
using Autodesk.Revit.Creation (this allows you to automatically and place create Revit Components)

Creating the extra Revit based Executive Commands

As you type you will notice that VS presents possible textstrings. This is very helpful in selecting the proper code. When the previews are shown, you can use the arrowkeys to get to the right one and hit Enter. This will automatically fill in the text in the coding screen, thus preventing a lot of typing mistakes.

End the line with a semicolon. It’s always needed to end a line with a punctuation mark. This is usually the semicolon, except when there is a bracket of any kind.
Besides this: keep in mind that these textstrings are case sensitive.

Depending on the type of Addin you want to create there will probably a need to also add some of the system containers too:

Using System.IO; (which allows you to read and write files)
Using System.Windows.Forms; (which allows you to make screens, forms and with this create a user interface for your Addin).

When typing the Using System.Windows.Forms you probably noticed that there was NO automated fill-in of the commands by VS. This happened because the Reference with the .NET Class was not yet created for this command. To make this work, you will also need to go to the Reference subscreen, right click on Reference and select Add Reference.

Now go the .NET tab and select System.Windows.Forms to add it to the References.

Adding System.Windows.Forms to the References.

Last remark before actually starting the programming

So, after this we’re kind of good to go. In the next parts of this weblog I’ll start trying to compile an Addin which allows you to automatically place Revit Components based on a point file.

Last tip I got before starting the actual work: when starting to program there’s a very useful viewsetting. Go to the View menu and click Error List. This opens up another subscreen which lists all coding errors (no errors does NOT mean the program will work, it just means there are no syntax errors in your code).

VS with Error List opened.

In this example the semicolon after the line “using System.Windows.Forms” is missing. You can double click on the error to jump to the text line to which it applies.


  1. Thanks for posting this useful content, Good to know about new things here, Let me share this, . LINUX training in pune


  2. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    tanki online | 2048 game| tanki online game

  3. Nice post i am really impressed with your post thank you for information

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร สล็อตออนไลน์ กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> Goldenslot
    สนใจร่วมสนุกกับ คาสิโนออนไลน์ คลิ๊กได้เลย
    มีทั้งคาสิโนออนไลน์ หวยออนไลน์ ฟุตบอลออนไลน์ สล็อตออนไลน์ และอื่นๆอีกมากมาย

  4. you can download setup for trail use from the official websote of norton, norton antivirus offers a good security and high standard of computer experience.

  5. Thanks for posting this useful content, Good to know about new things here, Let me share this
    CorVel Telehealth For PC

  6. Thanks for sharing such an Amazing information, I Couldn't leave without reading your blog. I have read another good blog, I think you have read it too. click here Trend Micro helpdesk