In Revit secondary development, compared to civil engineering module, there is piping system module. Connection between each MEP pipe fitting and pipe is controlled by Connector, thereby connecting the entire piping system in series. If you click pipe in LookUp, you can see it is divided into ConnectorManagement and All Refs two classes, both store Connector. People who just contacted might feel a bit messy.
If querying all intersecting pipes sequentially starting from sprinkler, we can get All Refs of each Connector, enter Connector then get Owner then enter Management of corresponding component to get all component connectors. Simply put, All Refs stores external connectors i.e. pipe fitting information connected to pipe, Connector of Management storage itself will be different according to set quantity.
If it is end key point, clicking All Refs will have two Connectors, one of which points to Piping System needs to be excluded in filter.
/// <summary>
/// Will filter pipes under specified sprinkler and first tee or elbow encountered
/// <remarks>Get vector value of second pipe connected to elbow as rotation axis
/// In sprinkler system there will only be pipe and Instance types, instance includes pipe fitting and sprinkler head</remarks>
/// </summary>
public void GetConnectors(Element fit, MepNode node)
{
bool baseIterator = true;
//1. Enter Management to get Set
ConnectorSet set = new ConnectorSet();
if (fit is FamilyInstance ins)
{
//fitting
set = ins.MEPModel.ConnectorManager.Connectors;
}
else
{
var pipe = fit as Pipe;
set = pipe?.ConnectorManager.Connectors;
var lc = pipe.Location as LocationCurve;
var dir = (lc.Curve as Line).Direction;
if (node.Vector is null) node.Vector = dir;
if (node.Vector.DotProduct(dir) < 0.002)
{
_pipe = pipe;
baseIterator = false;
}
}
if (baseIterator)
{
node.Next = new MepNode(fit);
node.Next.Vector = node.Vector;
//In this example except sprinkler there will be two Connectors pointing to two ends of connection
//If only one entrance, the other points to piping system
foreach (var s in set)
{
var connector = s as Connector;
//Exclude situation of piping system
//At this time find Connector connected to Connector at bottom of sprinkler
var allRefs = connector.AllRefs;
foreach (var allRef in allRefs)
{
var rf = allRef as Connector;
var ele = rf.Owner;
if (ele.Id != fit.Id && ele.GetType() != typeof(PipingSystem))
{
node.Next.Connectors.Add(rf);
if (node.Instance is null)
{
GetConnectors(ele, node.Next);
}
else
{
if (rf.Owner.Id == node.Instance.Id) continue;
GetConnectors(ele, node.Next);
}
}
}
}
}
}