Hello everybody,
Im trying to make a function that will take in a tpiece and return a coefficient base on a table from DIN 1988-300:
I get T pieces by collecting family instances and checking the part type in the MEPModel field.
After that, I retrieved the connectors from the T piece and obtained the flow values, but I can't determine the coefficients based on just that. I would need some way to identify which connector is going straight and which one is branching off.
I thought the angle property could help me here, but no luck—in the families I'm looking at, they are all 0. Any idea how to tackle this problem? How would i determine which connector is comming from the side at a t piece?
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Yes. You can look at the connector coordinate system:
Its Z axis point in the connector direction, so you can use that to determine the relative connector angles.
Thanks Jeremy,it works
Here is the code for the function:
public static Element AnalyzeTee2(Element element, Document doc)
{
Element elementAtAngle = null;
// Check if the element is a FamilyInstance
if (!PipeNetworkSplitter.isSplitter(element))
{
return null;
}
List<Connector> tpieceConnectors = getConnectors(element);
Connector connector1 = tpieceConnectors[0];
Connector connector2 = tpieceConnectors[1];
Connector connector3 = tpieceConnectors[2];
XYZ zVector1 = connector1.CoordinateSystem.BasisZ;
XYZ zVector2 = connector2.CoordinateSystem.BasisZ;
XYZ zVector3 = connector3.CoordinateSystem.BasisZ;
if (AreVectorsParallel(zVector1,zVector2)) elementAtAngle = getConnectingConnector(connector3).Owner;
if (AreVectorsParallel(zVector2,zVector3)) elementAtAngle = getConnectingConnector(connector1).Owner;
if (AreVectorsParallel(zVector1,zVector3)) elementAtAngle = getConnectingConnector(connector2).Owner;
return elementAtAngle;
}
public static bool AreVectorsParallel(XYZ vector1, XYZ vector2, double tolerance = 1e-6)
{
// Compute the cross product of the two vectors
XYZ crossProduct = vector1.CrossProduct(vector2);
// Check if the cross product is close to zero vector within the given tolerance
return crossProduct.IsAlmostEqualTo(XYZ.Zero, tolerance);
}
Thank you for the confirmation! Shared on the blog for posterity:
Can't find what you're looking for? Ask the community or share your knowledge.