The Revit MEP 2010 API

We already presented an analysis of the

MEP connectors

in Revit 2010, but a general introduction to the MEP-specific API is still missing.
Or was, until today.

Question:
What can I do with the Revit MEP API?
What’s new in Revit MEP 2010?
Are there any additions or enhancements specifically for the MEP flavour?
Any new content?

Answer:
The Revit 2010 API has been strongly enhanced with new MEP-specific features.
The main feature of the RME API is to provide read and write access to the Revit MEP model, including the following HVAC and piping data aspects and main components:

  • Traverse ducts, pipes, fittings and connectors in a system.
  • Add, remove and modify ducts, pipes and other equipment.
  • Read and modify system properties.
  • Determine whether a system is well-connected.

The new API features are listed in the sub-section ‘MEP API for ducts and pipes’ in the ‘What’s New’ section of the Revit API help file.
All of the new MEP-specific API functionality is located in the Autodesk.Revit.MEP namespace.
To understand the MEP functionality and API, it is useful to first know the hierarchical grouping of objects.
The main components are the systems, ducts, pipes, fittings and connectors:

  • System to manage the top level system properties.
  • Ducts and pipes to define the main flow elements.
  • Fittings to implement bends and branches in the system.
  • Connectors to hook up the ducts, pipes and fittings.

The classes MechanicalSystem and PipingSystem provide the following top-level system functionality:

  • Access to equipment, connectors and system type.
  • Access to system properties such as flow and static pressure.
  • Analysis of system contents: DuctNetwork or PipeNetwork.

The elements contained within a system are not automatically returned in the flow direction, and the TraverseSystem SDK sample demonstrates how to implement traversal in direction of flow for a given system.

The ducts and pipes are represented by the classes Duct, FlexDuct, Pipe and FlexPipe.
They provide the following functionality:

  • Read access to duct properties, types, and geometry.
  • Change duct or pipe type.
  • Move or layout duct or pipe.

The layout functionality can be driven by two points, one point and a connector, or two connectors.

The fittings are represented by family instances, which are created with dedicated Autodesk.Revit.Creation.Document methods New*Fitting, where * can be replaced by any one of Elbow, Tee, Cross, Takeoff, Transition, UnionFitting.
The fitting properties can be accessed through the FamilyInstance.MEPModel property.

The

MEP connectors

are represented by different classes depending on the context.
This caused some confusion, which is why this topic has already been discussed in a previous post.
In a family document, during the connector definition, we use the specialised classes DuctConnector, PipeConnector and ElectricalConnector.
In the project document, the connectors are represented using the Connector class.
The connector features include:

  • Read duct, pipe, and fitting connector properties such as Flow, Coefficient, Demand.
  • Access physical connector properties e.g. Origin, Angle, Height, Width, Radius.
  • The family connectors define Flow, Flow Configuration, Coefficients, Loss Method.
  • Change connector size and location.
  • Connect and disconnect.

For the element creation within a project environment, we have several new methods on the creation document:

  • New*System to create a new mechanical or piping system.
  • NewDuct, NewFlexDuct, NewPipe and NewFlexPipe to create new elements.
  • New*Fitting to create new fittings, with * being one of Cross, Elbow, TakeOff, TeeFitting, Transition, Union.

To create the connector definitions within the family context, the FamilyItemFactory class accessed through the Document.FamilyCreate property provides the following new methods:

  • NewDuctConnector
  • NewPipeConnector
  • NewElectricalConnector

The Revit SDK includes the following new MEP-specific sample applications to demonstrate the use of the new functionality:

  • AutoRoute: Route a set of ducts and fittings between a base air supply equipment and two terminals.
  • AvoidObstruction: Detect and resolve obstructions between ducts, pipes, and beams
  • TraverseSystem: Traverse a well-connected mechanical or piping system in the direction of flow
  • CreateAirHandler: Create an air handler and add connectors

The first three demonstrate new RME API features, the fourth is an MEP-specific family API sample.

These samples were also presented in the recent

Revit programming webcast
.

The MEP contents have also been extended.
One important new product feature is the interoperability with Inventor to support the MEP workflow.

Here is a vaguely related question on application compatibility between different flavours of Revit and between the 32 and 64 bit platforms:

Question:
Will a Revit plug-in assembly created with the 32-bit Revit MEP 2010 API work on 32-bit Revit Architecture 2010 and in 64-bit Revit MEP or Architecture 2010?

Answer:
If the plug-in makes use of MEP-specific functionality through the Revit API in some of its commands, then those commands will only work on Revit MEP.
You can query what flavour of Revit your plug-in is currently running on and enable or disable certain functionality accordingly.
The vast majority of the Revit API will work unchanged on all flavours.

Because the .NET framework creates assemblies that are not bound to a specific architecture, your application created in a 32-bit environment should also work unmodified in a 64-bit one.
You need to test this, though, to ensure that you have not inadvertently bound it to 32 bits in some way.


Comments

20 responses to “The Revit MEP 2010 API”

  1. Ivan Markov Avatar
    Ivan Markov

    Hi Jeremy,
    I am hoping you can point me to the right direction. I am building a custom printing utility for Revit and I need to be able to generate a preview for my users, before spooling the content to a printer. Is the functionality available through the API? If not can you point me in a general directions on how to create that functionality myself.
    Thanks

  2. Dear Ivan,
    You have a huge number of options and they obviously depend heavily on exactly what it is you are aiming to do. To start with, you could have a look at the PrintManager class, and the Revit SDK ViewPrinter sample.
    Cheers, Jeremy.

  3. Ivan Markov Avatar
    Ivan Markov

    Hi Jeremy,
    thank you for the response, but I think I did not explain properly. I have already looked at the example. What I was referring to is that with the Revit build in print dialog a user can generate a print preview of the current view, before they print. I have not been able to find a way to generate a print preview using the API and I was wandering if you can tell me if that is possible at all?

  4. Dear Ivan,
    Oh, I see. Thank you for the update and clarification. Nope, I do not believe there is any API access to that. You could try to simulate the required user input using one of the possibilities described in
    http://thebuildingcoder.typepad.com/blog/2009/05/vb-samples-and-other-questions.html#1
    Cheers, Jeremy.

  5. Jeremy,
    As usual, when I try too much and beat the problem to death and yet still can’t find an answer, I have to come back to you :)
    I am trying to create a print command that prints one pdf size. Everything is working except the sheets are not added to the print setting no matter what:
    the following three lines of code are taken from the ViewPrinter SDK sample, however, in my case, the viewSheetSet is not getting populated back to the CurrentViewSheetSet. I keep getting this message “This property is only available when user choose Select of Print Range.” at the execution of the third line.
    Please help (ps: I do have a printManager.PrintSetup.Save(); before this line, and I am using printManager.PrintRange = …PrintRange.Select;
    {

    ViewSheetSet viewSheetSet = m_doc.PrintManager.ViewSheetSetting.CurrentViewSheetSet;
    viewSheetSet.Views = selectedViews;
    m_doc.PrintManager.ViewSheetSetting.CurrentViewSheetSet = viewSheetSet;
    …}

  6. Dear Nadim,
    Please look at the discussion following the comment
    http://thebuildingcoder.typepad.com/blog/2009/06/creating-a-curved-beam.html?cid=6a00e553e16897883301157114b5ab970b#comment-6a00e553e16897883301157114b5ab970b
    It continues in an AUGI forum as well and presents a solution that may help.
    Cheers, Jeremy.

  7. thank you for the information. However, I had already tried that and got this message “There are no views/sheets selected.” and that is because the viewSheetSet is not being populated to CurrentViewSheetSet in the last line
    {
    m_doc.PrintManager.ViewSheetSetting.CurrentViewSheetSet = viewSheetSet;
    }
    I tested that with Object.Equal() method immediatly after, and it returns false, here it is:
    {
    System.Windows.Forms.MessageBox.Show(ptManager.ViewSheetSetting.CurrentViewSheetSet.Equals(tmpViewSheetSet).ToString());
    }
    please let me know what do you think?
    regards,

  8. Dear Nadim,
    I think that you might have told me and the other people reading this about your previous research and saved me the trouble to dig it up again for you. Other than that, I think that I cannot do much more to help, but maybe you can pick up the thread started by Pierre and Rod and find a workable solution for all of you together, and the rest of the community as well.
    Cheers, Jeremy.

  9. I once handled a question about adding views to CurrentViewSheetSet.
    It is a tricky here. We cannot assign another ViewSheetSet that owns views to CurrentViewSheetSet property. This cannot add views to CurrentViewSheetSet.
    We need to assign ViewSet to CurrentViewSheetSet.Views directly.
    for example, i created a macro in VSTA.
    public void Execute()
    {
    Document doc = this.ActiveDocument;
    try
    {
    //change printManager’s view set
    doc.BeginTransaction();
    //get current view setting viewset
    ViewSheetSetting vsst = doc.PrintManager.ViewSheetSetting;
    ViewSet vs = this.Create.NewViewSet();
    //get a sheet and insert it to the vs
    ElementIterator ei = doc.get_Elements(typeof(ViewSheet));
    ViewSheet vsPrint = null;
    while (ei.MoveNext())
    {
    vsPrint = ei.Current as ViewSheet;
    break;
    }
    if (vsPrint == null)
    {
    System.Windows .Forms.MessageBox.Show( “There is no view sheet in current project”);
    return;
    }
    vs.Insert(vsPrint);
    //vs.Insert(doc.ActiveView);
    vsst.CurrentViewSheetSet.Views = vs;
    bool bSuccess = vsst.Save();
    doc.EndTransaction();
    }
    catch (Exception ex)
    {
    System.Windows.Forms.MessageBox.Show(ex.Message);
    return;
    }
    }
    Then I run this macro, when calling this line bool bSuccess = vsst.Save();
    the error message is ¡°Attempt to modify the model outside of transaction¡±,
    This should remind Save() should be in a transaction. So I add doc.BeginTransaction and doc.EndTransaction.
    doc.BeginTransaction();
    bool bSuccess = vsst.Save();
    doc.EndTransaction();
    This changes made the macro works well.
    Cheers,
    Joe Ye

  10. Dear Joe,
    Thank you very much for the encompassing answer and for posting it here!
    Since it is such a large chunk of code, I should maybe promote this to a proper post one of these days for better readability and visibility.
    Cheers, Jeremy.

  11. I found the solution, here it is:
    you can’t assign directly like:
    …CurrentViewSheetSet = viewSheetSet
    you can’t use the insert method:
    …CurrentViewSheetSet.Insert(view)
    but what you can do is create a:
    ViewSet tmpViewSet = new ViewSet();
    and then populate it with all the views to print,
    at the end, just type:
    …CurrentViewSheetSet.Views = tmpViewSet;
    this should work.
    Regards,
    Nadim

  12. alright,
    I see that Joe already responed with the answer.
    correction: the second “can’t do” in my previous post is
    …CurrentViewSheetSet.Views.Insert(view);
    regards,
    Nadim

  13. Dear Nadim,
    Thank you very much for precisely pointing out the really important difference. I have seen similar situations a couple of times in the past, where the Revit API provides a property which returns a value and not a reference. If you modify the value returned, this will obviously not affect the internal state of Revit or the model. To change the state, you have to assign to the property instead.
    The other two situations in which we explicitly pointed out this kind of behaviour were
    http://thebuildingcoder.typepad.com/blog/2009/08/library-paths.html
    and
    http://thebuildingcoder.typepad.com/blog/2009/09/adding-a-category-to-a-parameter-binding.html
    Cheers, Jeremy.

  14. Thanks to the changes made to the PrintManager in Revit API 2010, I am back to the same problem. I have to spend alot of time on it again, and I really feel my blood pressure is going up because of this issue.
    I need to upgrade my printing application to Revit 2010; however, the same problem is happening again. The views that will be printed and added to a ViewSet named tmpViewSet are not been populated to the …CurrentViewSheetSet.Views even if write it as follows:
    ptManager.ViewSheetSetting.CurrentViewSheetSet.View = tmpViewSet;
    Whatever change the API developers did, it prevents this solution from working again.
    obvoisly, you can not say …CurrentViewSheetSet.Views.Insert(vw) because the Views collection is a read only.
    Pleeeeeeeeeeeeeeeeeease help or ask any insider how to populate the views to be printed to the ptManager…..Views property.
    Thanks in advance,
    Nadim

  15. Dear Nadim,
    I am actually not an expert in this area. Have you had a look at the recent post dealing with printing?
    http://thebuildingcoder.typepad.com/blog/2009/12/modify-the-dwf-export-filename.html
    Maybe Rod can help you?
    Cheers, Jeremy.
    P.S. I am totally allergic to “Pleeeeeeeeeeeeeeeeeease”.

  16. Jeremy,
    I found the solution, at least I fixed my problem.
    What I had to do is to SaveAs() the viewSheetSetting as follows:
    ViewSheetSetting viewSheetSetting = ptManager.ViewSheetSetting;
    ViewSheetSet viewsToPrint = viewSheetSetting.CurrentViewSheetSet;
    viewSheetSetting.SaveAs(“No one will guess this name”);
    /*
    here you add the code and place all views in a ViewSet
    and populate it back to ViewSheetSettting.CurrentViewSheetSet.Views
    The next step is the key step
    */
    viewSheetSetting.CurrentViewSheetSet = viewsToPrint;
    Is there any place where I can find some information regarding how revit process plotting. My biggest confusion is when am I using the in-session and when I am not.
    I hope this helps.
    Nadim

  17. Dear Nadim,
    Congratulations, and thank you very much for letting us know your solution!
    I am sure this will be a great help to others facing the same issue.
    Cheers, Jeremy.

  18. Caitlin Avatar
    Caitlin

    Hello Jeremy,
    I have a very specific question regarding the ‘NewDuctConnector’ Method. Is it possible to specify in which direction the duct connector faces given the specified planarFace? It seems like the method automatically chooses the normal to the planarFace, but for this one extrusion I created it defaults to a positive Z-direction which is opposite to the normal for the planarFace. I can manually ‘flip’ the normal in the Revit program but programatically it does not seem straight forward.
    I would greatly appreciate any response,
    Caitlin

  19. Dear Caitlin,
    We did indeed note an issue related to the connector direction of connectors added through the API. That has been resolved now, and should be fixed in the recent update. Could you try it out in the updated version, please?
    http://thebuildingcoder.typepad.com/blog/2010/06/revit-2011-web-update-1.html
    Since I will be going on holiday the next two weeks, I will not be able to answer any updates for quite a while from now on, so please be patient … Thank you!
    Cheers, Jeremy.

  20. Caitlin Avatar
    Caitlin

    Thank you! That was very helpful. Have a good vacation.
    Caitlin

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading