Making a revit addin has been a goal of mine for some time. Yesterday I finally succeeded, complete with ridiculous names, images and tasks completed.

The addin is simple and essentially useless, it assigns walls of a certain type to a workset (Github).

Learning C#

I learned C# mostly through Autodesk's tutorial on the Revit API, found here. C# is different enough from python  that it initimiated me.

A few examples:

  • Declare variable types
  • Cast variables
  • Compile your code etc.

 

Those familiar with C# probably know all of these items, it was fun to learn on my end coming from python. This video guided me in making the ribbon found in the user interface of revit.

You can see in the code below, if you know what a for loop is, you can piece together what these lines are doing, there are just a lot more { } everywhere:

foreach (Workset workset in worksetList)
{
   if (workset.Name.Contains("Concrete"))
       {
           ConcreteWalls = workset.Id.IntegerValue;
       }
}
TaskDialog.Show("Revit", ConcreteWalls.ToString());
// note we have now identified the Concrete shearwall workset

Learning C# sharp was relatively quick. My mind remembered the pains of learning python, but most of the struggles with python were due to never learning about object oriented programming. Classes, objects and everything that went along with an object oriented programming were easy enough to map from python to C#.

Learning C# taught me an important skill, the use of debugger. Why I never used this while coding in Python I will never know. Debuggers allow you to not have to print variables out all the time and appear to have a lot more power that I have not yet unleashed. In the code example above, I was able to watch the debugger stepping through the foreach loop for each workset in the project, and if the workset contains "Concrete" it steps out of the for loop. I look forward to learning more about debugging in both C# and python.

As with any new skill or programming language, intimidation and coding tutorials are the obstacles to progress. Once I actually started coding, debugging, and yes, print screening still, making the addin started to click. 

A negative of C#

To debug the program you have to start and close revit all the time, this is super time consuming! The ability to quickly whip up a revit idea in dynamo and python is really unparalleled. Getting instant feed back on the items in a list of variable is definitely valuable. If you know of a way to get around revit having to fire up each time a change is made to the code, please let me know.

C# Moving forward

C# appears powerful, but will only be reserved for projects that warrant the slow development process. One that comes to my mind is the revit rebar bender. Knowing C# will help me alleviate the limitations that the rebar adaptive component faced. C# is also supported by the ETABs API and I believe you can even have your very own button in the UI of ETABs like Revit. More work in the future...

Revit C Sharp

Our Sidebar

You can put any information here you'd like.

  • Latest Comments
  • retug on Transfer Diaphragm Design -

    @316Jq, The way I understand, the diaphragm design force (inertia force) per 12.10.1.1 is the inertia force.

    Using the blog example numbers let's say this is 1392 kips.

    The transfer diaphragm force could be estimated to be the delta in shears above and below the transfer level ~ (1500 -  …

  • 316Jq on Transfer Diaphragm Design -

    Just wonder how do you separate inertia force and the transfer force? The inertia force might be controlled by the Fpx,min per ASCE12.10-2,  while the transfer force might need to be multiplied by rho or omega. This is also briefly discussed in NHERP design guidance you used. 

  • retug on Section Cutter - ETABs Plugin -

    Hi Rodrigio, thanks for reaching out.

    My email is retug.austin@gmail.com, feel free to shoot me an email.

    The section cutter tool needs a bit of updating to work with the newer version of ETABs, but happy to discuss what you might have in mind for the add-in.

    Thanks