Create Pipe Method

Create Pipe Method

Create Pipe Method

The following function creates a new Pipe object in the Revit document through the Pipe.Create Constructor using two XYZ points. Similar concept can be applied to other MEPCurve Class objects as well, e.g. Duct, Cabletray.

using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Mechanical;
//Input Document
//Function returns pipe created
public Pipe CreatePipe(Document doc)
{
    //System Type (DomesticHotWater, DomesticColdWater, Sanitary, etc)
    MEPSystemType mepSystemType = new FilteredElementCollector(doc)
        .OfClass(typeof(MEPSystemType))
        .Cast<MEPSystemType>()
        .FirstOrDefault(sysType => sysType.SystemClassification == MEPSystemClassification.DomesticColdWater);
 
    //Pipe Type (Standard, ChilledWater)
    PipeType pipeType = new FilteredElementCollector(doc)
        .OfClass(typeof(PipeType))
        .Cast<PipeType>()
        .FirstOrDefault();
 
    //Level
    Level level = new FilteredElementCollector(doc)
        .OfClass(typeof(Level))
        .Cast<Level>()
        .FirstOrDefault();
 
    Pipe newPipe = Pipe.Create(doc, mepSystemType.Id, pipeType.Id, level.Id, XYZ.Zero, new XYZ(0, 0, 50));
 
    return newPipe;
}

Do take note that there are three different types of constructors for different use cases, refer to documentation, namely:

  • From one XYZ point to another XYZ point (See above example)
  • From one Connector to another Connector
  • From one Connector to a XYZ point

Methods to getting connectors from MEPCurve objects or MEPModel objects can be found in the respective embedded links. You can find the source code for the full implementation HERE! Happy coding!

Leave a Reply

Close Menu