Via the Autodesk.Revit.DB.Plumbing
namespace: There is a function:
public static Pipe Create(Document document, ElementId systemTypeId, ElementId pipeTypeId, ElementId levelId, XYZ startPoint, XYZ endPoint);
And you can use that in your code like:
XYZ fStartPoint = new XYZ(0.0, 0.0, 0.0); //Modify these values to your desired coordinates
XYZ fEndPoint = new XYZ(0.0, 0.0, 0.0); //Modify these values to your desired coordinates
ElementId pPipeTypeId = pPreviousPipe.PipeType.Id;
ElementId pPipeLevelId = pPreviousPipe.LevelId;
ElementId pSystemId = pPreviousPipe.MEPSystem.Id;
if (pPipeLevelId == ElementId.InvalidElementId)
{
Level lLevel = null;
using (Transaction pTrans = new Transaction(doc, "Get Level"))
{
pTrans.Start();
lLevel = Level.Create(doc, pPreviousPipe.LevelOffset;
pTrans.Commit();
}
pPipeLevelId = lLevel.Id;
}
Pipe.Create(doc, pSystemId, pPipeTypeId, pPipeLevelId, fStartPoint, fEndPoint);
There are overloads for the Create(...)
function, so take a look at those too. If you're connecting Pipe
s and FamilyInstance
s like fittings, you can use the
public static Pipe Create(Document document, ElementId pipeTypeId, ElementId levelId, Connector startConnector, Connector endConnector);
which will connect them directly via the Connector
s. As for offsetting the pipes, what I did above should suit you best. Good luck!
Added Note (edit)
And the Offset
in your second image refers to the Z
axis of your plane. You want to do something more like
var fTemp = pPreviousPipe.Location as LocationCurve;
var fEnd = fTemp.Curve.GetEndPoint(1);
//Index 0 is the beginning of the pipe (where user started drawing)
//Index 1 is the end of the pipe (where user stopped drawing)
XYZ fStartPoint = new XYZ(fEnd.X, fEnd.Y - .5, fEnd.Z);
double dPipeLength = 10.0;
XYZ fEndPoint = new XYZ(fStartPoint.X + dPipeLength, fStartPoint.Y, fStartPoint.Z);