예제 #1
0
        /// <summary>
        ///     Gets the nearest planar face by ray that room cener point to element center point.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="elm"></param>
        /// <param name="room"></param>
        /// <param name="doc"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        public static PlanarFace GetNearestPlanarFace <T>(this T elm, SpatialElement room, Document doc, View3D view) where T : Element
        {
            if (elm is null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            if (room is null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (view is null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var elmCenter = elm.GetBoundingBox(doc).GetBoxCenter();

            var roomCenter = room.GetBoundingBox(doc).GetBoxCenter();

            var direction = (elmCenter - roomCenter).Normalize();

            var elmFilter = new ElementClassFilter(elm.GetType());

            var intersector = new ReferenceIntersector(elmFilter, FindReferenceTarget.Face, view);

            var context = intersector.FindNearest(roomCenter, direction);

            doc.AutoTransaction(() =>
            {
                doc.CreateModelCurve(Line.CreateBound(roomCenter, elmCenter), out _);
            });

            if (context == null)
            {
                return(null);
            }

            var reference = context.GetReference();

            var refElm = doc.GetElement(reference.ElementId);

            var face = refElm.GetGeometryObjectFromReference(reference) as Face;

            if (face is PlanarFace planarFace)
            {
                return(planarFace);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        ///     Gets planar face list by ray that room cener point to element center point.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="elm"></param>
        /// <param name="room"></param>
        /// <param name="doc"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        public static List <PlanarFace> GetPlanarFaceList <T>(this T elm, SpatialElement room, Document doc, View3D view) where T : Element
        {
            if (elm is null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            if (room is null)
            {
                throw new ArgumentNullException(nameof(room));
            }

            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (view is null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            var elmCenter = elm.GetBoundingBox(doc).GetBoxCenter();

            var roomCenter = room.GetBoundingBox(doc).GetBoxCenter();

            var direction = (elmCenter - roomCenter).Normalize();

            var elmFilter = new ElementClassFilter(elm.GetType());

            var intersector = new ReferenceIntersector(elmFilter, FindReferenceTarget.Face, view);

            var contexts = intersector.Find(roomCenter, direction);

            var results = new List <PlanarFace>();

            foreach (var context in contexts)
            {
                var reference = context.GetReference();

                var refElm = doc.GetElement(reference.ElementId);

                var face = refElm.GetGeometryObjectFromReference(reference) as Face;

                if (face is PlanarFace planarFace)
                {
                    results.Add(planarFace);
                }
            }

            return(results);
        }
예제 #3
0
        /// <summary>
        ///     Creates CurtainSystem list.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="app"></param>
        /// <param name="room"></param>
        /// <param name="pnlType"></param>
        /// <param name="tplFileName"></param>
        public static List <CurtainSystem> CreateCurtainSystemListWithTrans(this Document doc, Application app, SpatialElement room, PanelType pnlType, string tplFileName)
        {
            if (doc == null)
            {
                throw new NullReferenceException(nameof(doc));
            }

            if (room == null)
            {
                throw new NullReferenceException(nameof(room));
            }

            if (app == null)
            {
                throw new NullReferenceException(nameof(app));
            }

            if (pnlType == null)
            {
                throw new NullReferenceException(nameof(pnlType));
            }

            if (tplFileName == null)
            {
                throw new NullReferenceException(nameof(tplFileName));
            }

            var roomc   = room.GetBoundingBox(doc).GetBoxCenter();
            var walls   = room.GetBoundaryWallList(doc);
            var results = new List <CurtainSystem>();

            foreach (var wall in walls)
            {
                var parm = new CurtainSystemParameter(wall, roomc, pnlType, tplFileName);

                results.Add(doc.CreateCurtainSystemWithTrans(app, parm));
            }

            return(results);
        }