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);
        }
    }
    
更多解密盡在唐僧課堂!


在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章