public static Dictionary <string, object> SplitDuctByPoints(Revit.Elements.Element element, List <Autodesk.DesignScript.Geometry.Point> points) { string result = ""; Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; List <Revit.Elements.Element> splitDucts = new List <Revit.Elements.Element>(); ElementId eId = doc.GetElement(element.UniqueId.ToString()).Id; Units units = doc.GetUnits(); FormatOptions fo = units.GetFormatOptions(UnitType.UT_Length); try { foreach (Autodesk.DesignScript.Geometry.Point p in points) { double pX = UnitUtils.ConvertToInternalUnits(p.X, fo.DisplayUnits); double pY = UnitUtils.ConvertToInternalUnits(p.Y, fo.DisplayUnits); double pZ = UnitUtils.ConvertToInternalUnits(p.Z, fo.DisplayUnits); XYZ ptBreak = new XYZ(pX, pY, pZ); ElementId pieceOfPipe = MechanicalUtils.BreakCurve(doc, eId, ptBreak); splitDucts.Add(doc.GetElement(pieceOfPipe).ToDSType(true)); } } catch (Exception ex) { result = ex.Message; } return(new Dictionary <string, object> { { "elements", splitDucts }, { "result", result } }); }
/// <summary> /// 打断管线 /// </summary> /// <param name="mepCurve"></param> /// <param name="ptBreak"></param> /// <returns>如果成功,返回新mepCurve元素的Id;如果失败,返回ElementId.InvalidElementId</returns> public static ElementId BreakCurve(this MEPCurve mepCurve, XYZ ptBreak) { if (mepCurve is Pipe || mepCurve is FlexPipe) { return(PlumbingUtils.BreakCurve(mepCurve.Document, mepCurve.Id, ptBreak)); } else if (mepCurve is Duct || mepCurve is FlexDuct) { return(MechanicalUtils.BreakCurve(mepCurve.Document, mepCurve.Id, ptBreak)); } return(ElementId.InvalidElementId); }
public static MEPCurve BreakCurve(this MEPCurve mep, XYZ point) { var locationline = mep.LocationLine(); var start = locationline.StartPoint(); var end = locationline.EndPoint(); var executeflag = point.IsOnLine(locationline) && point.DistanceTo(start) > 1d.MetricToFeet() && point.DistanceTo(end) > 1d.MetricToFeet(); if (!executeflag) { throw new Exception("点不在线上"); } var doc = mep.Document; #if Revit2016 return(null); #endif #if Revit2019 ElementId result = null; if (mep is Duct) { result = MechanicalUtils.BreakCurve(doc, mep.Id, point); } else if (mep is Pipe) { result = PlumbingUtils.BreakCurve(doc, mep.Id, point); } else if (mep is CableTray) { var newline1 = Line.CreateBound(start, point); var newline2 = Line.CreateBound(point, end); (mep.Location as LocationCurve).Curve = newline1; var newcabletray = CableTray.Create(doc, mep.GetTypeId(), point, end, mep.ReferenceLevel.Id); var para_w = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM); var para_H = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM); para_w.Set(mep.Width); para_H.Set(mep.Height); result = newcabletray.Id; } return(result.GetElement(doc) as MEPCurve); #endif }