Revit二开--管线打断功能

Revit二开–管线打断功能

唐僧解瓦 项目 github地址:https://github.com/binbinstrong/tangsengjiewa

	
	[Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.UsingCommandData)]
    class Cmd_MepCurveBreak : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection sel = uidoc.Selection;
            View acview = uidoc.ActiveView;
            //UIView acuivew = uidoc.Activeuiview();
            var eleref = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is MEPCurve),
                "拾取管线打断点");
            var pickpoint = eleref.GlobalPoint;
            var mep = eleref.GetElement(doc) as MEPCurve;
            var locationline = (mep.Location as LocationCurve).Curve as Line;
            pickpoint = pickpoint.ProjectToXLine(locationline); //ProjectToXLine 方法作用是 获取点投影到直线上的点
            var startpo = locationline.StartPoint();
            var endpo = locationline.EndPoint();
            var newstart = startpo;
            var newend = pickpoint;
            var newstart1 = pickpoint;
            var newend1 = endpo;
            Transaction ts = new Transaction(doc, "拾取管线打断点");
            try
            {
                ts.Start();
                var newmep = ElementTransformUtils.CopyElement(doc, mep.Id, new XYZ()).First().GetElement(doc) as MEPCurve;
                chagnemeplen(mep,newstart, newend);
                chagnemeplen(newmep, newstart1, newend1); 
                ts.Commit();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                if (ts.GetStatus() == TransactionStatus.Started)
                {
                    ts.RollBack();
                }
                //throw;
            }
            return Result.Succeeded;
        }
        void chagnemeplen(MEPCurve mep,XYZ p1,XYZ p2)
        {
            var locationline = (mep.Location as LocationCurve).Curve as Line;
            (mep.Location as LocationCurve).Curve = Line.CreateBound(p1, p2);
        }
    }
    
更多解密尽在唐僧课堂!


在这里插入图片描述

发布了47 篇原创文章 · 获赞 51 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/binbinstrong/article/details/102595979