revit secondary development of three-and four-perfect ideas

When the pipeline for generating found only tutorial example of the basic development of secondary elbow, then I add a generation example of the three-way and four-way.

Generating easiest bend, the book has tutorials, and generates lower bend angle requirements.

using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

[Transaction(TransactionMode.Manual)]
    class NewElbow : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            Selection sel = uiApp.ActiveUIDocument.Selection;

            // Select two tubes
            var reference1 = sel.PickObject (ObjectType.Element, "Please select the first pipe");
            MEPCurve duct1 = doc.GetElement (reference1) AS MEPCurve;

            var reference2 = sel.PickObject (ObjectType.Element, "select the second pipe");
            MEPCurve duct2 = doc.GetElement (Reference2) AS MEPCurve;

            //弯头
            ConnectTwoDuctsWithElbow(doc, duct1, duct2);

            return Result.Succeeded;
        }
        /// <summary>
        /// 连接管道
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="duct1"></param>
        /// <param name="duct2"></param>
        public static void ConnectTwoDuctsWithElbow(Document doc, MEPCurve duct1, MEPCurve duct2)
        {
            double minDistance = double.MaxValue;
            Connector connector1, connector2;
            connector1 = connector2 = null;

            foreach (Connector con1 in duct1.ConnectorManager.Connectors)
            {
                foreach (Connector con2 in duct2.ConnectorManager.Connectors)
                {
                    var dis = con1.Origin.DistanceTo(con2.Origin);
                    if (dis < minDistance)
                    {
                        minDistance = dis;
                        connector1 = con1;
                        connector2 = con2;
                    }

                }
            }

            if (connector1 != null && connector2 != null)
            {
                using (Transaction tran = new Transaction(doc))
                {
                    tran.Start("1033067630");

                    var elbow = doc.Create.NewElbowFitting(connector1, connector2);

                    tran.Commit();
                }
            }
        }
    }

Took a three-way, three things most important to note angle! ! angle! ! angle! ! , Perpendicular to the second tubes of the first tube should not exceed 1 °! Very strict!

There are primary and secondary order problem. As with the three-way ball valve insulation is required using the following protocol

[Transaction(TransactionMode.Manual)]
    class NewTeeFitting : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            Selection sel = uiApp.ActiveUIDocument.Selection;

            // Select two pipes
            var reference1 = sel.PickObject (ObjectType.Element, "Please select the first pipe");
            MEPCurve duct1 = doc.GetElement (reference1) AS MEPCurve;

            var reference2 = sel.PickObject (ObjectType.Element, "select the second pipe");
            MEPCurve duct2 = doc.GetElement (Reference2) AS MEPCurve;


            Curve curve1 = (doc.GetElement(reference1).Location as LocationCurve).Curve;

            Curve curve2 = (doc.GetElement(reference2).Location as LocationCurve).Curve;

            was ductList = GetMainDuct (duct1, duct2);

            MEPCurve MainDuct = ductList[0];//the main Pipe
            MEPCurve LessDuct = ductList[1];// the minor Pipe

            MEPCurve duct3 = null;//the main pipe

            IntersectionResultArray intersectPoint = new IntersectionResultArray();

            var x = curve1.Intersect(curve2, out intersectPoint);

            if (x == SetComparisonResult.Overlap)
            {
                using (Transaction tran = new Transaction(doc))
                {
                    tran.Start("1033067630");

                    var OrginPoint = intersectPoint.get_Item(0).XYZPoint;

                    var elementId = PlumbingUtils.BreakCurve(doc, MainDuct.Id, OrginPoint);

                    duct3 = doc.GetElement(elementId) as MEPCurve;

                    tran.Commit();
                }
            }


            ConnectTwoDuctsWithElbow(doc, MainDuct, duct3, LessDuct);

            return Result.Succeeded;
        }

        /// <summary>
        /// 区分主要管道与次要管道
        /// </summary>
        /// <param name="duct1"></param>
        /// <param name="duct2"></param>
        /// <returns></returns>
        public static List<MEPCurve> GetMainDuct(MEPCurve duct1, MEPCurve duct2)
        {
            List<MEPCurve> mEPCurves = new List<MEPCurve>();

            Curve curve1 = (duct1.Location as LocationCurve).Curve;
            Curve curve2 = (duct2.Location as LocationCurve).Curve;

            List<double> disList = new List<double>();
            double dis = double.MaxValue;
            XYZ pointA1 = curve1.GetEndPoint(0);
            XYZ pointA2 = curve1.GetEndPoint(1);
            XYZ pointB1 = curve2.GetEndPoint(0);
            XYZ pointB2 = curve2.GetEndPoint(1);

            var distance1 = curve2.Distance(pointA1);
            var distance2 = curve2.Distance(pointA2);
            var distance3 = curve1.Distance(pointB1);
            var distance4 = curve1.Distance(pointB2);

            disList.Add(distance1);
            disList.Add(distance2);
            disList.Add(distance3);
            disList.Add(distance4);

            disList.Min haze = ();
            where x = disList.IndexOf (DIS);

            if (x < 2)
            {
                mEPCurves.Add(duct2);
                mEPCurves.Add(duct1);
                return mEPCurves;
            }
            else
            {
                mEPCurves.Add(duct1);
                mEPCurves.Add(duct2);
                return mEPCurves;
            }


        }

        /// <summary>
        /// 创建连接
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="duct1">主要管道1</param>
        /// <param name="duct2">主要管道2</param>
        /// <param name="duct3">次要管道</param>
        public static void ConnectTwoDuctsWithElbow(Document doc, MEPCurve duct1, MEPCurve duct2, MEPCurve duct3)
        {
            double minDistance = double.MaxValue;
            Connector connector1, connector2, connector3;
            connector1 = connector2 = connector3 = null;

            foreach (Connector con1 in duct1.ConnectorManager.Connectors)
            {
                foreach (Connector con2 in duct2.ConnectorManager.Connectors)
                {
                    var dis = con1.Origin.DistanceTo(con2.Origin);
                    if (dis < minDistance)
                    {
                        minDistance = dis;
                        connector1 = con1;
                        connector2 = con2;
                    }

                }
            }

            minDistance = double.MaxValue;//重置
            foreach (Connector con3 in duct3.ConnectorManager.Connectors)
            {
                var dis = con3.Origin.DistanceTo(connector1.Origin);
                if (dis < minDistance)
                {
                    minDistance = dis;
                    connector3 = con3;
                }
            }


            if (connector1 != null && connector2 != null && connector3 != null)
            {
                using (Transaction tran = new Transaction(doc))
                {
                    tran.Start("xx");

                    var elbow = doc.Create.NewTeeFitting(connector1, connector2, connector3);

                    tran.Commit();
                }
            }
        }
    }

 

4 is the final pass, the problem is still to be noted that the angle, and the connection parameters, the first parameter and the second common line, the third and fourth parameters collinear (i.e., the same line)

[Transaction(TransactionMode.Manual)]
    class NewCross : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            MEPCurve duct3, duct4;
            duct3 = duct4 = null;
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            Selection sel = uiApp.ActiveUIDocument.Selection;

            // Select two duct
            var reference1 = sel.PickObject (ObjectType.Element, "Please select the first duct");
            MEPCurve duct1 = doc.GetElement (reference1) AS MEPCurve;

            var reference2 = sel.PickObject (ObjectType.Element, "select the second duct");
            MEPCurve duct2 = doc.GetElement (Reference2) AS MEPCurve;

            Curve curve1 = (doc.GetElement(reference1).Location as LocationCurve).Curve;

            Curve curve2 = (doc.GetElement(reference2).Location as LocationCurve).Curve;

            IntersectionResultArray intersectPoint = new IntersectionResultArray();

            var x = curve1.Intersect(curve2, out intersectPoint);

            if (x == SetComparisonResult.Overlap)
            {
                using (Transaction tran = new Transaction(doc))
                {
                    tran.Start("x");

                    var OrginPoint = intersectPoint.get_Item(0).XYZPoint;

                    var elementId3 = PlumbingUtils.BreakCurve(doc, duct1.Id, OrginPoint);

                    duct3 = doc.GetElement(elementId3) as MEPCurve;//duct1 and duct3 in one line 

                    var elementId4 = PlumbingUtils.BreakCurve(doc, duct2.Id, OrginPoint);

                    duct4 = doc.GetElement(elementId4) as MEPCurve;//duct2 and duct4 in one line

                    tran.Commit();
                }
            }

            ConnectTwoDuctsWithElbow(doc, duct1, duct3, duct2, duct4);//四通

            return Result.Succeeded;
        }
        /// <summary>
        /// 创建连接,四通前2个共线,后2个共线
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="duct1"></param>
        /// <param name="duct2"></param>
        /// <param name="duct3"></param>
        public static void ConnectTwoDuctsWithElbow(Document doc, MEPCurve duct1, MEPCurve duct2, MEPCurve duct3, MEPCurve duct4)
        {
            double minDistance = double.MaxValue;
            Connector connector1, connector2, connector3, connector4;
            connector1 = connector2 = connector3 = connector4 = null;

            foreach (Connector con1 in duct1.ConnectorManager.Connectors)
            {
                foreach (Connector con2 in duct2.ConnectorManager.Connectors)
                {
                    var dis = con1.Origin.DistanceTo(con2.Origin);
                    if (dis < minDistance)
                    {
                        minDistance = dis;
                        connector1 = con1;
                        connector2 = con2;
                    }

                }
            }

            minDistance = double.MaxValue;//重置
            foreach (Connector con3 in duct3.ConnectorManager.Connectors)
            {
                var dis = con3.Origin.DistanceTo(connector1.Origin);
                if (dis < minDistance)
                {
                    minDistance = dis;
                    connector3 = con3;
                }
            }

            minDistance = double.MaxValue;//重置
            foreach (Connector con4 in duct4.ConnectorManager.Connectors)
            {
                var dis = con4.Origin.DistanceTo(connector1.Origin);
                if (dis < minDistance)
                {
                    minDistance = dis;
                    connector4 = con4;
                }
            }


            if (connector1 != null && connector2 != null && connector3 != null && connector4 != null)
            {
                using (Transaction tran = new Transaction(doc))
                {
                    tran.Start("xx");

                    var elbow = doc.Create.NewCrossFitting(connector1, connector2, connector3, connector4);

                    tran.Commit ();
                }
            }
        }
    }
Related Bowen: three-way structure Thinking

BQ44F-BQ45F Way insulation valve
Q944F-Q945F electric ball valve
Q644F-Q645F pneumatic ball valve
Q44F-Q45F stainless steel ball valve
Q14F-Q15F Tee with threaded ball
Q44H-Q44Y , Q45H Q45Y- hard sealing ball valve
Q44F- Q45F -way seal valve four



Guess you like

Origin www.cnblogs.com/sktvalves/p/10974881.html