123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Electrical;
- using Autodesk.Revit.DB.Mechanical;
- using Autodesk.Revit.DB.Plumbing;
- using SAGA.RevitUtils.Extends;
- namespace SAGA.RevitUtils.MEP
- {
- public static class MEPCurveExtend
- {
- /// <summary>
- ///
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="mepCurve"></param>
- /// <param name="start"></param>
- /// <param name="end"></param>
- /// <returns></returns>
- public static T Copy<T>(this T mepCurve, XYZ start, XYZ end) where T: MEPCurve
- {
- T element = default(T);
- Document doc = mepCurve.Document;
- ICollection<ElementId> source = doc.CopyElement(mepCurve.Id, XYZ.Zero);
- doc.Regenerate();
- if (source.Count > 0)
- {
- element = doc.GetElement(source.FirstOrDefault<ElementId>()) as T;
- element.UpdateLocation<T>(start, end);
- }
- return element;
- }
- public static Connector GetConnector(this MEPCurve mepCurve, XYZ point)
- {
- return mepCurve.ConnectorManager.Connectors.GetList().FirstOrDefault<Connector>(t=>t.Origin.IsEqual(point));
- }
- /// <summary>
- /// 获取MEPCurve的所以点集合
- /// </summary>
- /// <param name="MEPCurve"></param>
- /// <returns></returns>
- public static List<XYZ> GetPoints(this MEPCurve MEPCurve)
- {
- return new List<XYZ> { MEPCurve.Location.GetLine().StartPoint(), MEPCurve.Location.GetLine().EndPoint() };
- }
- /// <summary>
- /// 获取与指定Connector相连接的Connector
- /// </summary>
- /// <param name="mepCurve"></param>
- /// <param name="point"></param>
- /// <returns></returns>
- public static Connector GetReferrenceConnector(this MEPCurve mepCurve, XYZ point)
- {
- Connector connector = mepCurve.GetConnector(point);
- if (connector.IsConnected)
- {
- foreach (Connector connector2 in connector.AllRefs.GetList())
- {
- if ((connector2.Owner.Id.IntegerValue != mepCurve.Id.IntegerValue) && (connector2.ConnectorType != ConnectorType.Logical))
- {
- return connector2;
- }
- }
- }
- return null;
- }
- public static List<Connector> GetReferrenceConnectors(this MEPCurve mepCurve)
- {
- List<Connector> list = new List<Connector>();
- foreach (Connector connector in mepCurve.GetAllConnectors())
- {
- if (connector.IsConnected)
- {
- foreach (Connector connector2 in connector.AllRefs.GetList())
- {
- if (!connector2.Owner.Id.Equals(mepCurve.Id))
- {
- list.Add(connector2);
- }
- }
- }
- }
- return list;
- }
-
- public static void Refurbish<T>(this T mepCurve) where T: MEPCurve
- {
- LocationCurve location = mepCurve.Location as LocationCurve;
- mepCurve.Document.RotateElement(mepCurve, location.GetLine(), 6.2831853071795862);
- }
- public static Tuple<T, Line> ToTuple<T>(this T mepCurve) where T: MEPCurve
- {
- return new Tuple<T, Line>(mepCurve, mepCurve.GetCurve() as Line);
- }
- public static void UpdateLocation<T>(this T mepCurve, XYZ start, XYZ end) where T: MEPCurve
- {
- if (!start.IsEqual(end, 0.0))
- {
- LocationCurve location = mepCurve.Location as LocationCurve;
- Line axis = start.NewLine(end);
- location.Curve = axis;
- mepCurve.Document.RotateElement(mepCurve, axis, Math.PI*2);
- }
- }
- public static void UpdateMepCurve(this MEPCurve conduit, XYZ point, XYZ sourcePoint)
- {
- Curve curve = conduit.Location.GetCurve();
- bool flag = curve.StartPoint().IsEqual(sourcePoint, 0.0);
- LocationCurve location = conduit.Location as LocationCurve;
- Curve curve3 = null;
- if (flag)
- {
- curve3 = Line.CreateBound(point, curve.EndPoint());
- }
- else
- {
- curve3 = Line.CreateBound(curve.StartPoint(), point);
- }
- location.Curve = curve3;
- conduit.Document.Regenerate();
- }
- }
- }
|