Revit二次开发_计算管道长度时折算管件

        Revit中统计出来的管道长度是实际的管道长度,而传统算量是把管件占的长度也计算到管道中的,虽说从理论来说Revit的量更准确,但在不讨论对错的情况下,倘若我希望兼容传统的算量规则的话,也是可以让Revit自动把管件长度也折算到管道里面的。

        折算的逻辑其实比较简单,首先获得管道,查询一下管道的连接件是否有连接有管件,如果连接了的话就计算连接件到族位置点的距离,将这段距离与管道的长度相加即可获得折算后长度。

        要注意的是这样的折算对族的位置点是有要求的,用自带的常规管件来举例的话,弯头、三通这些都是可以完美的将管件长度折算过去的,因为它们的位置点就是管道的交点,而变径则会将长度折算到其中一端,因为它的位置点就在其中一个连接件上。

以下代码:

                //管道长度
                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("goodwish", Math.Round(UnitUtils.ConvertFromInternalUnits(pipeLength, DisplayUnitType.DUT_MILLIMETERS), 3).ToString() + " => " + Math.Round(UnitUtils.ConvertFromInternalUnits(convertLength, DisplayUnitType.DUT_MILLIMETERS), 3).ToString());

猜你喜欢

转载自blog.csdn.net/imfour/article/details/80194616