Revit 二次开发传入点,传出CurveArray

传入顺序点List<XYZ>,传出纯直线CurveArray,或者传出带一条Arc的CurveArray,Arc线位置通过传入位置下标确定;

传入循序点List<List<XYZ>>,传出纯直线CurveArrArray,或者传出带一条Arc的CurveArrArray,Arc线位置通过传入位置下标确定;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Bhidi.Revit.CreateVolute.Model;
using CC.ExpandPack.Rebar_CommonUtil;
using CC.Utils.Extensions;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using static UIFramework.Widget.CustomControls.NativeMethods;
using Document = Autodesk.Revit.DB.Document;
using Form = Autodesk.Revit.DB.Form;

namespace Bhidi.Revit.Commands
{
    [Transaction(TransactionMode.Manual)]
    public class TestDemo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var app = commandData.Application;
            var doc = app.ActiveUIDocument.Document;
            using (Transaction tr = new Transaction(doc, "test"))
            {
                tr.Start();

                double T = 0;

                bool IsOutletBranchHole = true;
                bool OutletBranchHoleNo = true;

                CurveArrArray curveArrArray19 = new CurveArrArray();
                List<List<XYZ>> listlist = new List<List<XYZ>>();


                if (IsOutletBranchHole)//勾选出支线洞
                {
                    double number = 2;
                    double spacing = 53000/304.8;
                    double holeWidth = 6000 / 304.8;
                    double holeHeight = 6500 / 304.8;
                    double topArchHeight = 0;
                    double bottomElevation = 844.5 *1000/ 304.8;
                    double distanceFromSideWall = 9550 / 304.8; ;
                    double drainageB = 300 / 304.8;
                    double drainageH = 400 / 304.8;
                    //double drainageH = 0;
                    double liningT;
                    double bottomT = 200 / 304.8;
                    
                    double sprayT = 100 / 304.8;
                    double drainageT = 100 / 304.8;

                    double bottomheight = bottomElevation - 840 * 1000 / 304.8;

                    if (OutletBranchHoleNo)//无衬砌
                    {
                        liningT = 0;
                    }
                    else
                    {
                        liningT = 500 / 304.8;
                    }

                    if (topArchHeight == 0)
                    {
                        topArchHeight = holeWidth / 4;
                    }


                    for (int i = 0; i < number; i++)
                    {
                        if (drainageH <= bottomT)//水沟高度小于底板厚,底板底面是平的情况
                        {
                            XYZ point1 = new XYZ(0 + distanceFromSideWall + i * spacing, 0 - 0 - T - 0, bottomheight - bottomT);
                            XYZ point2 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT * 2 + sprayT * 2 + holeWidth, 0 - 0 - T - 0, bottomheight - bottomT);

                            XYZ point3 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT * 2 + sprayT * 2 + holeWidth, 0 - 0 - T - 0, bottomheight + holeHeight - topArchHeight);
                            XYZ point4 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + holeWidth / 2, 0 - 0 - T - 0, bottomheight + holeHeight + liningT + sprayT);
                            XYZ point5 = new XYZ(0 + distanceFromSideWall + i * spacing, 0 - 0 - T - 0, bottomheight + holeHeight - topArchHeight);

                            //Curve line1 = Line.CreateBound(point1, point2);
                            //Curve line2 = Line.CreateBound(point2, point3);
                            //Curve line3 = Arc.Create(point3, point5, point4);
                            //Curve line4 = Line.CreateBound(point5, point1);

                            //CurveArray curveArray18 = new CurveArray();
                            //curveArray18.Append(line1);
                            //curveArray18.Append(line2);
                            //curveArray18.Append(line3);
                            //curveArray18.Append(line4);
                            //curveArrArray19.Append(curveArray18);

                            List<XYZ> list = new List<XYZ>() { point1,point2,point3,point4,point5};
                            //List<XYZ> list = new List<XYZ>() { point5,point4,point3,point2,point1};
                            //List<XYZ> list = new List<XYZ>() { point2,point1,point5,point4,point3};
                            //List<XYZ> list = new List<XYZ>() { point1,point5,point4,point3,point2};
                            //listlist.Add(list);

                            CurveArray curveArray18 = ListPointsToCurveArray(list,2);
                            curveArrArray19.Append(curveArray18);
                        }
                        else
                        {

                            XYZ point1 = new XYZ(0 + distanceFromSideWall + i * spacing, 0 - 0 - T - 0, bottomheight - drainageH);
                            XYZ point2 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + drainageB + drainageT, 0 - 0 - T - 0, bottomheight - drainageH);
                            XYZ point3 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + drainageB + drainageT, 0 - 0 - T - 0, bottomheight - bottomT);

                            XYZ point4 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + holeWidth - drainageB - drainageT, 0 - 0 - T - 0, bottomheight - bottomT);
                            XYZ point5 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + holeWidth - drainageB - drainageT, 0 - 0 - T - 0, bottomheight - drainageH);
                            XYZ point6 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT * 2 + sprayT * 2 + holeWidth, 0 - 0 - T - 0, bottomheight - drainageH);

                            XYZ point7 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT * 2 + sprayT * 2 + holeWidth, 0 - 0 - T - 0, bottomheight + holeHeight - topArchHeight);
                            XYZ point8 = new XYZ(0 + distanceFromSideWall + i * spacing + liningT + sprayT + holeWidth / 2, 0 - 0 - T - 0, bottomheight + holeHeight + liningT + sprayT);
                            XYZ point9 = new XYZ(0 + distanceFromSideWall + i * spacing, 0 - 0 - T - 0, bottomheight + holeHeight - topArchHeight);

                            //Curve line1 = Line.CreateBound(point1, point2);
                            //Curve line2 = Line.CreateBound(point2, point3);
                            //Curve line3 = Line.CreateBound(point3, point4);
                            //Curve line4 = Line.CreateBound(point4, point5);
                            //Curve line5 = Line.CreateBound(point5, point6);
                            //Curve line6 = Line.CreateBound(point6, point7);
                            //Curve line7 = Arc.Create(point7, point9, point8);
                            //Curve line8 = Line.CreateBound(point9, point1);

                            //CurveArray curveArray18 = new CurveArray();
                            //curveArray18.Append(line1);
                            //curveArray18.Append(line2);
                            //curveArray18.Append(line3);
                            //curveArray18.Append(line4);
                            //curveArray18.Append(line5);
                            //curveArray18.Append(line6);
                            //curveArray18.Append(line7);
                            //curveArray18.Append(line8);
                            //curveArrArray19.Append(curveArray18);

                            List<XYZ> list = new List<XYZ>() { point1, point2, point3, point4, point5,point6,point7,point8,point9 };
                            listlist.Add(list);


                            //CurveArray curveArray18 = ListPointsToCurveArray(list,6);
                            //curveArrArray19.Append(curveArray18);





                        }
                    }

                }

                curveArrArray19 = ListPointsToCurveArray(listlist);
                
                // 首先创建几何平面
                Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisY, XYZ.Zero);
                // 根据几何平面创建工作平面
                SketchPlane sketchPlane = SketchPlane.Create(doc, plane);


                // 调用API创建拉伸(实心正方体)
                Extrusion rectExtrusion = doc.FamilyCreate.NewExtrusion(true, curveArrArray19, sketchPlane, 10);





                tr.Commit();
            }
            
            return Result.Succeeded;
        }

        /// <summary>
        /// 传入点列表,传出CurveArray
        /// </summary>
        /// <param name="listPoints"></param>
        /// <returns></returns>
        public static CurveArray ListPointsToCurveArray(List<XYZ> listPoints)
        {

            CurveArray curveArray = new CurveArray();
            Curve curve = null;
            for (int i = 0; i < listPoints.Count(); i++)
            {
                if (i == listPoints.Count() - 1)
                {
                    curve = Line.CreateBound(listPoints[i], listPoints[0]);
                    curveArray.Append(curve);
                }
                else
                {
                    curve = Line.CreateBound(listPoints[i], listPoints[i + 1]);
                    curveArray.Append(curve);
                }
            }
            return curveArray;

        }

        /// <summary>
        /// 传入点列表,传出CurveArray,location为Arc线起始位置下标值
        /// </summary>
        /// <param name="listPoints"></param>
        /// <param name="location">下标值</param>
        /// <returns></returns>
        public static CurveArray ListPointsToCurveArray(List<XYZ> listPoints, int location)
        {

            CurveArray curveArray = new CurveArray();
            Curve curve = null;
            //Arc线在前三点
            if (location == 0)
            {
                curve = Arc.Create(listPoints[0], listPoints[2], listPoints[1]);
                curveArray.Append(curve);
                for (int i = 2; i < listPoints.Count(); i++)
                {
                    if (i == listPoints.Count() - 1)
                    {
                        curve = Line.CreateBound(listPoints[i], listPoints[0]);
                        curveArray.Append(curve);
                    }
                    else
                    {
                        curve = Line.CreateBound(listPoints[i], listPoints[i + 1]);
                        curveArray.Append(curve);
                    }
                }
            }
            //Arc线在后三点
            else if (location == listPoints.Count() - 3 || location == listPoints.Count() - 2|| location == listPoints.Count() - 1)
            {
                location = listPoints.Count() - 3;
                for (int i = 0; i < location; i++)
                {
                    curve = Line.CreateBound(listPoints[i], listPoints[i + 1]);
                    curveArray.Append(curve);
                }

                curve = Arc.Create(listPoints[location], listPoints[location + 2], listPoints[location + 1]);
                curveArray.Append(curve);

                curve = Line.CreateBound(listPoints[location + 2], listPoints[0]);
                curveArray.Append(curve);

            }
            //Arc线在中间三点
            else
            {
                for (int i = 0; i < location; i++)
                {
                    curve = Line.CreateBound(listPoints[i], listPoints[i + 1]);
                    curveArray.Append(curve);
                }
                curve = Arc.Create(listPoints[location], listPoints[location + 2], listPoints[location + 1]);
                curveArray.Append(curve);

                for (int i = location + 2; i < listPoints.Count()-1; i++)
                {
                    curve = Line.CreateBound(listPoints[i], listPoints[i + 1]);
                    curveArray.Append(curve);
                }

                curve = Line.CreateBound(listPoints[listPoints.Count()-1], listPoints[0]);
                curveArray.Append(curve);
            }
            return curveArray;

        }






        /// <summary>
        ///  传入List<List<XYZ>>,传出CurveArrArray
        /// </summary>
        /// <param name="listListPoints"></param>
        /// <returns></returns>
        //public static CurveArrArray ListListPointsToCurveArrArray(List<List<XYZ>> listListPoints)
        //{
        //    CurveArrArray curveArrArray = new CurveArrArray();
        //    CurveArray curveArray = null;
        //    for (int i = 0; i < listListPoints.Count(); i++)
        //    {
        //        curveArray = ListPointsToCurveArray(listListPoints[i]);
        //        curveArrArray.Append(curveArray);
        //    }
        //    return curveArrArray;
        //}

        /// <summary>
        ///  传入List<List<XYZ>>,传出CurveArrArray
        /// </summary>
        /// <param name="listListPoints"></param>
        /// <returns></returns>
        public static CurveArrArray ListPointsToCurveArray(List<List<XYZ>> listListPoints)
        {
            CurveArrArray curveArrArray = new CurveArrArray();
            CurveArray curveArray = null;
            for (int i = 0; i < listListPoints.Count(); i++)
            {
                curveArray = ListPointsToCurveArray(listListPoints[i]);
                curveArrArray.Append(curveArray);
            }
            return curveArrArray;
        }

        /// <summary>
        ///  传入List<List<XYZ>>,传出CurveArrArray
        /// </summary>
        /// <param name="listListPoints"></param>
        /// <returns></returns>
        public static CurveArrArray ListPointsToCurveArray(List<List<XYZ>> listListPoints, int location)
        {
            CurveArrArray curveArrArray = new CurveArrArray();
            CurveArray curveArray = null;
            for (int i = 0; i < listListPoints.Count(); i++)
            {
                curveArray = ListPointsToCurveArray(listListPoints[i],location);
                curveArrArray.Append(curveArray);
            }
            return curveArrArray;
        }





    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值