该文参照https://blog.csdn.net/imfour/article/details/80194616,记录下来加深记忆,再者便于以后查看
Revit中统计出来的管道长度是实际的管道长度,而传统算量是把管件占的长度也计算到管道中的。
折算的逻辑:首先获得管道,查询管道的连接件是否连接有管件,如果连接了的话就计算连接件到族位置点的距离,将这段距离与管道的长度相加即可获得折算后长度。
注意:这样的折算对族的位置点有要求,用Revit自带的常规管件举例说明;对于弯头、三通,因为他们的位置点是管道的交点,因此可以完美的将管件长度折算过去的;而对于变径,因为他们的位置点在其中的一个连接件上,因此长度会折算到其中一端。
实现代码如下:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Reference refer = uiDoc.Selection.PickObject(ObjectType.Element,"Pick a pipe");
Pipe pipe = doc.GetElement(refer) as Pipe;
if (null == pipe)
{
return Result.Failed;
}
double pipeLength = pipe.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
double convertLength = pipeLength;
foreach (Connector con in pipe.ConnectorManager.Connectors)
{
if (con.IsConnected)
{
foreach (Connector ref_con in con.AllRefs)
{
if ((BuiltInCategory)ref_con.Owner.Category.Id.IntegerValue == BuiltInCategory.OST_PipeFitting && (ref_con.ConnectorType == ConnectorType.End || ref_con.ConnectorType == ConnectorType.Curve || ref_con.ConnectorType == ConnectorType.Physical))
{
convertLength += con.Origin.DistanceTo((ref_con.Owner.Location as LocationPoint).Point);
break;
}
}
}
}
TaskDialog.Show("PipeLength",Math.Round(UnitUtils.ConvertFromInternalUnits(pipeLength,DisplayUnitType.DUT_MILLIMETERS),2).ToString());
TaskDialog.Show("PipeTotalLength", Math.Round(UnitUtils.ConvertFromInternalUnits(convertLength, DisplayUnitType.DUT_MILLIMETERS), 2).ToString());
return Result.Succeeded;
}