One of the main new features in the Revit 2014 API is the possibility to make use of external services to redefine the algorithms used for certain MEP related calculations.
The external services framework was introduced in Revit 2013, but not used in that version.
The recent listing of Revit 2014 API functionality and SDK samples points out that this is one of the highlights of the new API, and yet no sample using it has been published yet.
Let's rectify that right here and now.
Built-in External Services
Revit MEP 2014 makes use of the external services itself. The service implementations live in the MEPCalculation sub-folder of 'C:\Program Files\Autodesk\Revit 2014\AddIns'.
It contains the following add-in manifests and .NET assemblies, with the DLLs listed under the add-in manifests loading them:
- FittingAndAccessoryCalculationManaged.dll
- FittingAndAccessoryCalculationUIServers.addin
- FittingAndAccessoryCalculationUIServers.dll
- MEPCalculation.addin
- FittingAndAccessoryCalculationServers.dll
- StraightSegmentCalculationServers.dll
- PressureLossReport.addin
- PressureLossReport.dll
A very similar structure was extracted and released in a pre-release API sample on the Revit beta site as an example of implementing a custom external service, but never made it into the final release.
Prompted and supported by our MEP expert Martin Schmid, I now took a look at that and adapted it to the current Revit 2014 API.
Here are the steps and results:
- The UserMepCalculation sample
- Concepts and Use Cases
- Migration of the pre-alpha version
- Test run
- Download
The UserMepCalculation Sample
The UserMepCalculation add-in is an external application implementing user-defined MEP calculation solver external services that override Revit’s default MEPCalculation solvers and reports listed above, in particular:
- System pressure loss report
- Straight segment calculation
- Fitting and accessory calculation
The UserMepCalculation Visual Studio solution contains the following four C# projects:
- FittingAndAccessoryCalculationServers
- FittingAndAccessoryCalculationUIServers
- PressureLossReport
- StraightSegmentCalculationServers
Concepts and Use Cases
Actually, digging in deeper, the sample addresses these six separate concepts:
- Pipe Segment Pressure Loss Calculation
- Pipe Fitting/Accessory Pressure Loss Calculation
- Pipe Fixture Units to Volume Flow conversion Calculation
- Duct Segment Pressure Loss Calculation
- Duct Fitting/Accessory Pressure Loss Calculation
- Pressure Loss Report
Migration of the Pre-alpha Version
Compiling the original pre-alpha version of this add-in produced the following initial list of 3 errors and 6 warnings.
I applied the disable architecture mismatch warning utility DisableMismatchWarning.exe, removing the warnings, leaving just 3 errors.
All three are similar, complaining that the three server implementations for pipe plumbing fixture flow and duct and pipe pressure drop, derived from the three interfaces IPipePressureDropServer, IDuctPressureDropServer and IPipePlumbingFixtureFlowServer, are not fulfilling their contract that requires them to implement the GetHtmlDescription member method.
Once the three methods were added, the compilation proceeded one step further and reported the next 4 errors, all referring to an erroneous call to an InnerDiameter method. That property was since renamed to InsideDiameter. After fixing that as well, the sample builds with zero errors and warnings.
It makes use of some unnecessary internal project settings that I cleaned up and removed as far as possible. Some remnants are still left, though. Among other things, the projects are set up to build specific 32 and 64 bit versions, although they are all identical, being standard .NET IL assemblies.
Once this was cleaned up, compiled and installed, it could be tested.
Test Run
To use and test, build and install the add-in. Note that the new user defined alternate calculation methods are now available and can be selected via Manage > MEP Settings > Mechanical Settings > Duct Settings and Pipe Settings > Calculation.
User duct pressure drop:
User pipe pressure drop:
User plumbing fixture flow:
Let's examine a system pressure-loss report. Note that the project-defined user interface now appears after launching Analyze > Reports & Schedules > Pipe Pressure Loss Report.
I copied the default pressure loss report transformation PressureLossReport.xslt from the above-mentioned MEPCalculation folder and renamed it to UserPressureLossReport.xslt.
The standard Revit pressure loss command now picks up my redefined calculation rules and created this pressure loss report from the Revit MEP basic sample project rme_basic_sample_project.rvt.
Download
Here is UserMepCalculation.zip containing the complete source code, Visual Studio solution, add-in manifest and some documentation on the custom calculation and report add-in.
I am off to Australia Sunday evening to hold a Revit API training there next week, and want to do some climbs in the Furka pass this weekend before leaving, so wish me luck!
Jeremy, using this method, could you theoretically calculate the friction loss of sprinkler piping systems?
To do so, in addition to what you show, it would need to be able to know pipe/fitting elevations (pressure loss due to elevation), take into account pressure increases due to fire pumps, take out flows due to open hydrants, and only flow sprinklers (with a given k-factor) which are set to "flowing" (in the sprinkler family), at a specified minimum pressure.
You would also need a script that adds node tags to every junction/equipment like inlet/outlet of fire pumps.
If you could do all that, sprinkler layout technicians like me (and our companies) would be paying you around $1000-5000 for each license of your add-on... There are only two other companies that have Revit "solutions" for fire sprinkler hydraulics right now, and both rely on external programs or import/export functionality, both are buggy and no good, and probably will never utilize this feature because they want to keep the hefty $5000-12000 pricetag for their external software.
Posted by: Anon | December 06, 2013 at 13:38
Can you provide instructions on how to build and install the add-in?
Posted by: Gary | December 16, 2013 at 12:56
Dear Gary,
The procedure is identical for all Revit add-ins. It is described in full detail in the DevTV and interactive tutorials provided by the Revit developer centre and getting started materials:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
Cheers, Jeremy.
Posted by: Jeremy Tammik | December 20, 2013 at 09:43
Jeremey,
I have a comment and question about this addin.
Under:
static public void getSectionsFromSystem(MEPSystem system, List sections)
I had to change this line:
MEPSection section = system.GetSectionByNumber(ii);
to
MEPSection section = system.GetSectionByIndex(ii);
Because the sections weren't necessarily in numerical order, and also didn't always start at one. Maybe I misunderstood what you were doing there, but I was having a rough time getting all the sections until I changed this to index.
My question is, when I use section.TotalPressureLoss, I get a double of 9.27246709... The API documentation under "MEPSection.TotalPressureLoss Property" states that the default value for this is Kgf per square feet, which converts to almost 4 inches of water, way beyond what's actually in my 2 diffuser system. Is KgF per square feet correct? Pascals, inhg, KgF per square meter, stones, slugs, furlongs, yards and atmospheres, don't seem to correspond with the Revit reported value (using the system inspector) of 0.1222531 inwg either.
As always thank you for this blog and the examples you provide.
Posted by: Matt | April 09, 2015 at 13:27
Jeremey,
Have you seen in the API a way to turn off system calculations for all piping and duct work instead of individually as currently required?
Posted by: Arif Hanif | April 17, 2015 at 11:54
Dear Arif (or Arief :-),
No, I am not aware of any such switch.
However, in the far distant past, I sometimes ran an MEP-specific add-in that only manipulated generic Revit element parameters in Revit Architecture, with no Revit MEP machinery available.
That enabled me to make changes to the parameters and thus change the MEP model without any recalculations being triggered.
Cheers, Jeremy.
Posted by: Jeremy Tammik | April 22, 2015 at 09:22