123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /* ==============================================================================
- * 功能描述:SpaceExtend
- * 创 建 者:Garrett
- * 创建日期:2017/11/21 11:55:16
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- namespace SAGA.RevitUtils.Extends
- {
- /// <summary>
- /// SpaceExtend
- /// </summary>
- public static class SpaceExtend
- {
- /// <summary>
- /// 获取空间在平面上的范围的点集合
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static List<XYZ> GetPlaneVertexes(this Space space)
- {
- List<XYZ> xyzs = new List<XYZ>();
- var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
- if (segments != null)
- {
- foreach (IList<Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
- {
- foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
- {
- //此处可能需要排序
- var startXyz = boundarySegment.GetCurve().GetEndPoint(0);
- var endXyz = boundarySegment.GetCurve().GetEndPoint(1);
- if (!xyzs.Contains(startXyz, new XyzEqualComparer()))
- xyzs.Add(startXyz);
- if (!xyzs.Contains(endXyz, new XyzEqualComparer()))
- xyzs.Add(endXyz);
- }
- }
- }
- return xyzs;
- }
- public static List<XYZ> GetPlaneOutVertexes(this Space space)
- {
- List<XYZ> xyzs = new List<XYZ>();
- var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
- if (segments != null)
- {
- foreach (IList<BoundarySegment> segmentList in segments)
- {
- foreach (BoundarySegment boundarySegment in segmentList)
- {
- //此处可能需要排序
- //var startXyz = boundarySegment.GetCurve().GetEndPoint(0);
- //var endXyz = boundarySegment.GetCurve().GetEndPoint(1);
- //if (!xyzs.Contains(startXyz, new XyzEqualComparer()))
- // xyzs.Add(startXyz);
- //if (!xyzs.Contains(endXyz, new XyzEqualComparer()))
- // xyzs.Add(endXyz);
- var inputPoints = boundarySegment.GetCurve().GetPoints();
- foreach (var inputPoint in inputPoints)
- {
- if (!xyzs.Contains(inputPoint, new XyzEqualComparer()))
- xyzs.Add(inputPoint);
- }
- }
- break;
- }
- }
- return xyzs;
- }
- /// <summary>
- /// 获取轮廓顶点
- /// </summary>
- /// <param name="sgements"></param>
- /// <returns></returns>
- public static List<XYZ> GetBoundaryVertexes(this IList<BoundarySegment> sgements)
- {
- List<XYZ> xyzs = new List<XYZ>();
- foreach (BoundarySegment boundarySegment in sgements)
- {
- var inputPoints = boundarySegment.GetCurve().GetPoints();
- foreach (var inputPoint in inputPoints)
- {
- if (!xyzs.Contains(inputPoint, new XyzEqualComparer()))
- xyzs.Add(inputPoint);
- }
- }
- return xyzs;
- }
- /// <summary>
- /// 获取轮廓相关path
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static List<List<XYZ>> GetBoundaryVertexes(this Space space)
- {
- List<List<XYZ>> paths = new List<List<XYZ>>();
- var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
- if (segments != null)
- {
- foreach (IList<BoundarySegment> segmentList in segments)
- {
- paths.Add(segmentList.GetBoundaryVertexes());
- }
- }
- return paths;
- }
- /// <summary>
- /// 获取所有的Space
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="bic"></param>
- /// <returns></returns>
- public static List<Space> GetSpaces(this Document doc)
- {
- return doc.GetElements(typeof(SpatialElement)).Where(t=>t is Space).Cast<Space>().ToList();
- }
- /// <summary>
- /// 空间底部标高
- /// </summary>
- /// <param name="wall"></param>
- /// <returns></returns>
- public static Level GetBaseLevel(this Space space)
- {
- return space.GetParameterElement(BuiltInParameter.ROOM_LEVEL_ID) as Level;
- }
- /// <summary>
- /// 空间底部偏移
- /// </summary>
- /// <returns></returns>
- public static double GetBaseOffSet(this Space space)
- {
- return space.GetParameterDouble(BuiltInParameter.ROOM_LOWER_OFFSET);
- }
- /// <summary>
- /// 获取底部高度
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static double GetBaseStaticHeight(this Space space)
- {
- return space.GetBaseLevel().Elevation + space.GetBaseOffSet();
- }
-
- /// <summary>
- /// 空间顶部标高
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static Level GetTopLevel(this Space space)
- {
- return space.GetParameterElement(BuiltInParameter.ROOM_UPPER_LEVEL) as Level;
- }
- /// <summary>
- /// 空间顶部偏移
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static double GetTopOffSet(this Space space)
- {
- return space.GetParameterDouble(BuiltInParameter.ROOM_UPPER_OFFSET);
- }
- /// <summary>
- /// 获取顶部高度
- /// </summary>
- /// <param name="space"></param>
- /// <returns></returns>
- public static double GetTopStaticHeight(this Space space)
- {
- return space.GetTopLevel().Elevation + space.GetTopOffSet();
- }
- }
- }
|