The time is overdue to migrate the Visual Studio Revit Add-In Wizards to Revit 2017.
This time, instead of a simple flat migration like in previous years, I decided to set up a new Visual Studio C# .NET Revit add-in project manually, by hand, completely from scratch, just to see whether anything significant changed since I did that last, and to ensure that the wizard is really using all the required Visual Studio settings.
I tried it out in by implementing a buildingSMART BCF API sample client.
Basically, that requires the following steps:
- Create a new pure Visual Studio class library
- Rename
Class1
toCommand
- Add references to the Revit API assemblies
- Implement an external command
- Implement an add-in manifest
- Define an add-in GUID
- Implement a post-build event to auto-install the add-in
The BCF API and a Sample Client
To try out these steps, I made use of a brand new sample project that I implemented in response to the Revit API discussion forum thread inquiring about support for the BCF API:
Question: Can anyone answer if Revit supports the BCF API to allow for third party integrations?
Answer: I searched the Internet for 'bcf api' and found the BuildingSMART BCF-API GitHub repository.
Is that what you are talking about?
Being a REST API, you can use it perfectly well from your own .NET add-ins.
The BCF API GitHub repo points to a C# client, the BcfApiExampleClient.
You can try integrating that very code into a Revit add-in and see how it goes.
Out of interest, I took a slightly deeper look.
I see that BCF stands for BIM Collaboration Format.
I also see that the C# sample can easily be integrated into a Revit add-in.
Question: Does the Revit API create the JSON for BCF or would we be required to create it ourselves via the add-in?
Answer: I was not aware of BCF until you raised this question, and I am pretty sure that Revit does nothing to support it.
If it is BCF specific, you will probably have to create it with your own custom add-in.
I created a new project to try out converting the BcfApiExampleClient sample to a Revit add-in, RvtBcfApiExampleClient.
It is a pure and simple REST API client.
I had some issues getting both the original sample and my Revit version up and running.
They were resolved over the week-end, however, and both the stand-alone sample client and the new Revit add-in version now work fine.
Here are some screen snapshots running the Revit add-in version:
The first step is the log in to the BIM-IT server:
As usual, this authorisation process returns an access token:
Finally, the sample simply lists all existing projects, of which I possess exactly zero:
If you are interested in diving deeper into the BCF API, please note the comment by Georg Dangl, saying, "in December we had another Hackathon in Munich where Veni Lillkall created a small sample app in C#. That might give you some ideas how to use the BCF API itself."
The Kayak Framework – an Easy Way to Speak HTTP with .NET
One interesting aspect of the BCF-API sample is its use of the Kayak framework – an easy way to speak HTTP with .NET, published in 2010 by Benjamin van der Veen, including Kayak sample code:
- Kayak is a lightweight HTTP server for the CLR, and the Kayak Framework is a utility for mapping HTTP requests to C# method invocations. With Kayak, you can skip the bulk, hassle, and overhead of IIS and ASP.NET. Kayak enables you to do more with less syntax, and is easy to configure to work in any way you care to dream up.
- Kayak is a simple server with an easy-to-use request framework. It automatically maps HTTP verb/path combinations to your methods, deserialises arguments to invocations of those methods from the query string or JSON request body, and serialises the return values as JSON. It's behaviour is configurable, yet simple to use and understand thanks to its limited scope.
Manual Setup of a Revit Add-In
As said, I used the BCF API client sample project to record exactly how to manually set up a Visual Studio C# .NET Revit add-in from scratch.
Here are the detailed individual steps I performed for this, with links to the corresponding commits in the GitHub repository:
- Added pure Visual Studio class library
- Renamed Class1 to Command and edited properties
- Added Revit API assemblies and implemented external command
- Added add-in manifest
- Added add-in manifest
- Added GUID using guidize.exe
- Implemented post-build event to auto-install add-in for Revit to find
- Successfully tested
The result is RvtBcfApiExampleClient release 2017.0.0.0, which is just a naked Revit 2017 C# .NET add-in skeleton.
The final working version presented above after fixing the initial problems with the login process is captured in release 2017.0.0.4.
As said, next I will use the generated files to update the Visual Studio Revit add-in wizard for Revit 2017.