It's been a while since I talked about External Services.
The External Services framework was initially introduced and used sparingly in the Revit 2013 MEP API.
The framework for handling referenced file resources is also implemented as an external service, using an implementation called the ExternalResourceService.
The motivation to continue this discussion now was given by Arnošt Löbel's class SD10752 on Revit External Services at Autodesk University 2015 in Las Vegas.
Many thanks to our incomparable hare Likk'mm, who laid the trail and provided the GPS track.
The Revit External Services framework enables developers to tailor the behavior of built-in Revit features to a level impossible to achieve with conventional external command-based add-ins. External Services have been used as a base to support customized MEP (mechanical, electrical, and plumbing) calculations, access externally stored data, replace built-in export/import filters, and many other Revit features. As Revit continues to grow there are new external services introduced with every major release, which gives developers new opportunities to provide their solutions on top of the Revit core functionality. Unfortunately, this feature has not been widely used by the yet, possibly due to the lack of comprehensive documentation, which is exactly the gap this class will attempt to fill. We explain the framework's main ideas, clearly illustrate the most anticipated uses and present a hands-on coding approach using a simple MEP friction calculator as an example.
- Learn how to identify all the parts that make up the Framework of External Services
- Discover the framework's main workflows, expectations, and limitations
- Learn how to find, organize, and use built-in external servers and services
- Learn how to design and implement a custom server for a published service (e.g., a MEP friction calculator)
Below are Jeremy's session notes taken during the presentation, followed by the official handout and class material.
This framework was introduced in Revit two years ago.
There is scant documentation for it.
Here is the agenda:
- Five-mile view, philosophy and design.
- Classes, implementation, workflows.
- Code samples.
It could be used, e.g., to replace a spell checker. Note that this is a purely hypothetical example for the audience to better understand the workflow. Spell-checking in Revit is not really implemented as an external service.
In a nutshell: delegate a process to an external application for redefinition, enabling feature componentising and behaviour customisation.
The ApplicationInitialized event was implemented two years back explicitly so that external servers can register after all external services have been registered, i.e., after all OnStartup calls have completed.
Currently, we are renovating Revit inside out and adding a large number of services.
We implemented two sample applications just for this class:
Note that these samples currently register their service in external commands.
This is totally unrealistic and only intended for demonstration purposes.
A real external server would register its service during start-up instead.
Note that the Revit SDK samples are not designed to be perfect and fully fleshed out, just demonstrate the basic code using the API.
The first sample is the Server Explorer. It lists all external servers and the services they provide.
Here are the results of running the server explorer sample in Revit 2016 SP2:
MEP calculations are one of the most important uses of external services.
As you can see from the output above, there are currently four servers for duct fitting pressure drop calculation.
The second example is a Revit MEP calculation external service sample for a pressure drop calculation.
It was implemented specifically for this AU class and, as mentioned, uses external commands to add and remove the calculator. A proper calculator will be implemented as an ExternalDBApplication with no external commands involved.
It currently just demonstrates the principles and returns hardcoded dummy calculation results.
The two sample applications discussed above are included in the zip file containing the SD10752 class material.
Jeremy's note to self: the Revit 2014 UserMepCalculation sample is now superseded by this one and should be replaced.
Here is Arnošt's handout document. The slide deck is very similar.
Many thanks to Arnošt for preparing and presenting all this important material!