Revit二次开发—管道打断

       早就想写点东西和大家分享了,但是介于自己的水平有限,迟迟没有发布技术文章和大家交流。进入正题之前给大家先奉上一碗心灵鸡汤,我的revit二次开发之路,走的非常的不顺畅,走了非常多的弯路,经历了很多艰苦的时刻,但是我没有放弃,每个人也不一样,相信你们很快的入门并且很快进步的,只要你们也和我一样不放弃不抛弃。经过不懈的努力,终于能在今天发布自己的第一篇技术博客,对我来说,这是一个具有重要意义的时刻。声明:本人现阶段发表的文章,都是基础入门级,重在于解惑刚入门的同行们,介于水平,文章难免出错,欢迎各位批评指正,一起探讨,一起进步。话不多说,进入正题。

主要代码:

 public void BreakMEP(Document doc, Selection selection)
        {
            //选择需要打断的MEP
            Reference reference = selection.PickObject(ObjectType.Element, new PipeSelectionFilter(doc),"请选择需要打断的管道");
            //获得需要打断MEP的位置信息
            Element element = doc.GetElement(reference);
            Pipe pipe = element as Pipe;
            LocationCurve pipeLocationCurve = pipe.Location as LocationCurve;
            //MEP上获得两个点
            XYZ firstPoint = selection.PickPoint("请选择第一个打断点");
            XYZ projectFirstPoint = pipeLocationCurve.Curve.Project(firstPoint).XYZPoint;
            XYZ secondPoint = selection.PickPoint("请选择第二个打断点");
            XYZ projectSecondPoint = pipeLocationCurve.Curve.Project(secondPoint).XYZPoint;

            //通过判断得到管道的新的位置基线
            Curve newCurve1 = null;
            Curve newCurve2 = null;
            if (projectFirstPoint.DistanceTo(pipeLocationCurve.Curve.GetEndPoint(0)) < projectSecondPoint.DistanceTo(pipeLocationCurve.Curve.GetEndPoint(0)))
            {
                newCurve1 = Line.CreateBound(pipeLocationCurve.Curve.GetEndPoint(0), projectFirstPoint) as Curve;
                newCurve2 = Line.CreateBound(projectSecondPoint, pipeLocationCurve.Curve.GetEndPoint(1)) as Curve;
            }
            else
            {
                newCurve1 = Line.CreateBound(pipeLocationCurve.Curve.GetEndPoint(1), projectFirstPoint) as Curve;
                newCurve2 = Line.CreateBound(projectSecondPoint, pipeLocationCurve.Curve.GetEndPoint(0)) as Curve;
                
            }


            //将原来的管道复制一根 并得到其位置信息
            Pipe copyPipe = doc.GetElement(ElementTransformUtils.CopyElement(doc, pipe.Id, new XYZ(0, 0, 0)).ElementAt(0)) as Pipe;
            LocationCurve copyPipeLocationCurve = copyPipe.Location as LocationCurve;
            //设置新的位置基线
            pipeLocationCurve.Curve = newCurve1;
            copyPipeLocationCurve.Curve = newCurve2;


        }



你可能感兴趣的:(Revit二次开发—管道打断)