Esempio n. 1
0
        /// <summary>
        /// 射线法获取房间吊顶高度,单位foot
        /// </summary>
        /// <param name="room"></param>
        /// <param name="pointInRoom">房间内一点,请确保该点在房间下楼板和上天花板内,否则计算值错误</param>
        /// <param name="currDocument">当前文件,射线法需要用到</param>
        /// <returns></returns>
        public static double GetRoomCeilingHeightByRay(this Room room, XYZ pointInRoom, Document currDocument)
        {
            if (room.Document.IsLinked && currDocument == null)
            {
                throw new InvalidOperationException("如果房间是链接文件中的房间,必须传递当前文件currDocument参数");
            }

            ElementFilter        elementFilter;
            ReferenceIntersector referenceIntersector;

            //向上找天花板
            elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_Ceilings);

            //射线法需要的三维视图,很关键,找不好就会找不到想要的结果
            FilteredElementCollector collector = new FilteredElementCollector(currDocument);
            //待改进
            var view3D = collector.OfClass(typeof(View3D)).Cast <View3D>().FirstOrDefault <View3D>(v3 => !(v3.IsTemplate));

            referenceIntersector = RevitExtensions.GetReferenceIntersector(
                view3D,
                room.Document.IsLinked,
                findReferenceTarget: FindReferenceTarget.All,
                targetElementIds: null,
                elementFilter: elementFilter);

            var topReference = referenceIntersector.FindNearest(pointInRoom, XYZ.BasisZ);

            if (topReference == null)
            {
                return(double.NaN);
            }

            //向下找楼板
            elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);
            referenceIntersector.SetFilter(elementFilter);

            var bottomReference = referenceIntersector.FindNearest(pointInRoom, XYZ.BasisZ.Negate());

            if (bottomReference == null)
            {
                return(double.NaN);
            }

            return(topReference.Proximity + bottomReference.Proximity);
        }
Esempio n. 2
0
        private static Element GetSegmentElementByRay(Document document, Curve segmentCure, bool isCounterclockwise)
        {
            double stepInRoom    = 0.1;
            XYZ    direction     = (segmentCure.GetEndPoint(1) - segmentCure.GetEndPoint(0)).Normalize();
            var    leftDirection = new XYZ(-direction.Y, direction.X, direction.Z);
            XYZ    upDir         = 1 * XYZ.BasisZ;

            XYZ toRoomVec = isCounterclockwise ? stepInRoom * leftDirection : stepInRoom *leftDirection.Negate();

            XYZ pointBottomInRoom = segmentCure.Evaluate(0.5, true) + toRoomVec;

            XYZ startPoint = pointBottomInRoom + upDir;
            XYZ toWallDir  = isCounterclockwise ? leftDirection.Negate() : leftDirection;

            //默认过滤 墙 柱子 门 幕墙嵌板
            var filters = new List <ElementFilter> {
                new ElementCategoryFilter(BuiltInCategory.OST_Walls),
                new ElementCategoryFilter(BuiltInCategory.OST_Columns),
                new ElementCategoryFilter(BuiltInCategory.OST_Doors),
                new ElementCategoryFilter(BuiltInCategory.OST_CurtainWallPanels),   //幕墙嵌板
            };
            var orFilter = new LogicalOrFilter(filters);

            //射线法需要的三维视图,很关键,找不好就会找不到想要的结果
            FilteredElementCollector collector = new FilteredElementCollector(document);
            //待改进
            var view3D = collector.OfClass(typeof(View3D)).Cast <View3D>().FirstOrDefault <View3D>(v3 => !(v3.IsTemplate));

            var referenceIntersector = RevitExtensions.GetReferenceIntersector(
                view3D,
                true,
                findReferenceTarget: FindReferenceTarget.All,
                targetElementIds: null,
                elementFilter: orFilter);

            var reference = referenceIntersector.FindNearest(startPoint, toWallDir);

            Element boundaryElement = null;

            if (reference != null && reference.Proximity < MathHelper.Eps + stepInRoom)
            {
                boundaryElement = reference.GetElementByReferenceWithContext(document);
            }
            return(boundaryElement);
        }