Revit中计算管道的总长--折算管件

该文参照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;
    }
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值