示例#1
0
        static public bool IsElementCollideRoom(Room room, Element elInsert)
        {
            // Проверка параметров Room у FamilyInstance
            FamilyInstance fi = elInsert as FamilyInstance;

            if (fi != null && (fi.Room?.Id == room.Id || fi.ToRoom?.Id == room.Id || fi.FromRoom?.Id == room.Id))
            {
                return(true);
            }

            // Проверка bbox
            BoundingBoxXYZ bb = elInsert.get_BoundingBox(null);
            BoundingBoxContainsPointFilter filterMin = new BoundingBoxContainsPointFilter(bb.Min);
            BoundingBoxContainsPointFilter filterMax = new BoundingBoxContainsPointFilter(bb.Max);

            filterMin.Tolerance = filterMax.Tolerance = 1;
            bool inter = filterMin.PassesFilter(room.Document, room.Id) || filterMax.PassesFilter(room.Document, room.Id);

            return(inter);
        }
示例#2
0
        static public List <Room> GetCollidedRooms(Element el)
        {
            // Проверка параметров Room у FamilyInstance
            FamilyInstance fi = el as FamilyInstance;

            if (fi != null)
            {
                Room[] rooms = new Room[] { fi?.Room, fi?.FromRoom, fi?.ToRoom };
                if (rooms.Any(x => x != null))
                {
                    return(rooms.Where(x => x != null).ToList());
                }
            }

            BoundingBoxXYZ bb = el.get_BoundingBox(null);
            BoundingBoxContainsPointFilter filterMin = new BoundingBoxContainsPointFilter(bb.Min);
            BoundingBoxContainsPointFilter filterMax = new BoundingBoxContainsPointFilter(bb.Max);

            filterMin.Tolerance = filterMax.Tolerance = 1;

            ElementFilter filter = new LogicalOrFilter(filterMin, filterMax);

            return(new FilteredElementCollector(el.Document).OfCategory(BuiltInCategory.OST_Rooms).WherePasses(filter).Cast <Room>().ToList());
        }
示例#3
0
        public List <SegmentData> CollectSegmentData(List <LinkElementId> exteriorElementIds, bool includeLinkedModel)
        {
            var segmentDataList = new List <SegmentData>();

            try
            {
                var options = new SpatialElementBoundaryOptions();
                options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                var segments = RoomObj.GetBoundarySegments(options);
                foreach (var segmentList in segments)
                {
                    foreach (var segment in segmentList)
                    {
                        var sData = new SegmentData(segment);
#if RELEASE2015
                        Element element = segment.Element;
#else
                        var element = RoomDocument.GetElement(segment.ElementId);
#endif

                        if (null != element)
                        {
                            if (null != element.Category)
                            {
                                Wall wall      = null;
                                var  transform = Transform.Identity;
                                if (element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_Walls))
                                {
                                    wall = element as Wall;
                                    if (null != wall)
                                    {
                                        var linkIds = from linkId in exteriorElementIds where linkId.HostElementId == wall.Id select linkId;
                                        if (linkIds.Any())
                                        {
                                            sData.IsExteriror = true;
                                        }
                                    }
                                }
                                else if (includeLinkedModel && element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_RvtLinks))
                                {
                                    var instance = element as RevitLinkInstance;
                                    transform = instance.GetTotalTransform();
                                    var linkDoc = instance.GetLinkDocument();

                                    var centerPoint = sData.BoundaryCurve.Evaluate(0.5, true);
                                    centerPoint = transform.Inverse.OfPoint(centerPoint);

                                    var bbFilter = new BoundingBoxContainsPointFilter(centerPoint);

                                    var collector = new FilteredElementCollector(linkDoc);
                                    var walls     = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall)).WherePasses(bbFilter).WhereElementIsNotElementType().ToElements().Cast <Wall>().ToList();
                                    if (walls.Count > 0)
                                    {
                                        wall = walls.First();
                                        var linkIds = from linkId in exteriorElementIds where linkId.LinkedElementId == wall.Id && linkId.LinkInstanceId == instance.Id select linkId;
                                        if (linkIds.Any())
                                        {
                                            sData.IsExteriror = true;
                                        }
                                    }
                                }

                                if (null != wall)
                                {
                                    sData.WallId = wall.Id;
                                    if (wall.WallType.Kind == WallKind.Curtain)
                                    {
                                        sData.VisibleCurves.Add(sData.BoundaryCurve);
                                        sData.GetViewPoints(true);
                                        segmentDataList.Add(sData);
                                    }
                                    else
                                    {
                                        var windowCurves = GetWindowsDoorCurves(wall, sData.BoundaryCurve, transform);
                                        if (windowCurves.Any())
                                        {
                                            sData.VisibleCurves.AddRange(windowCurves);
                                            sData.GetViewPoints(false);
                                            segmentDataList.Add(sData);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            sData.GetViewPoints(true);
                            segmentDataList.Add(sData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
            return(segmentDataList);
        }
示例#4
0
        public List <SegmentData> CollectSegmentData(List <LinkElementId> exteriorElementIds)
        {
            List <SegmentData> segmentDataList = new List <SegmentData>();

            try
            {
                SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
                options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = m_room.GetBoundarySegments(options);
                foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
                {
                    foreach (Autodesk.Revit.DB.BoundarySegment segment in segmentList)
                    {
                        SegmentData sData = new SegmentData(segment);
                        if (null != segment.Element)
                        {
                            if (null != segment.Element.Category)
                            {
                                Wall      wall      = null;
                                Transform transform = Transform.Identity;
                                if (segment.Element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_Walls))
                                {
                                    wall = segment.Element as Wall;
                                    if (null != wall)
                                    {
                                        var linkIds = from linkId in exteriorElementIds where linkId.HostElementId == wall.Id select linkId;
                                        if (linkIds.Count() > 0)
                                        {
                                            sData.IsExteriror = true;
                                        }
                                    }
                                }
                                else if (segment.Element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_RvtLinks))
                                {
                                    RevitLinkInstance instance = segment.Element as RevitLinkInstance;
                                    transform = instance.GetTotalTransform();
                                    Document linkDoc = instance.GetLinkDocument();

                                    XYZ centerPoint = sData.BoundaryCurve.Evaluate(0.5, true);
                                    centerPoint = transform.Inverse.OfPoint(centerPoint);

                                    BoundingBoxContainsPointFilter bbFilter = new BoundingBoxContainsPointFilter(centerPoint);

                                    FilteredElementCollector collector = new FilteredElementCollector(linkDoc);
                                    List <Wall> walls = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall)).WherePasses(bbFilter).WhereElementIsNotElementType().ToElements().Cast <Wall>().ToList();
                                    if (walls.Count > 0)
                                    {
                                        wall = walls.First();
                                        var linkIds = from linkId in exteriorElementIds where linkId.LinkedElementId == wall.Id && linkId.LinkInstanceId == instance.Id select linkId;
                                        if (linkIds.Count() > 0)
                                        {
                                            sData.IsExteriror = true;
                                        }
                                    }
                                }

                                if (null != wall)
                                {
                                    sData.WallId = wall.Id;
                                    if (wall.WallType.Kind == WallKind.Curtain)
                                    {
                                        sData.VisibleCurves.Add(sData.BoundaryCurve);
                                        sData.GetViewPoints(true);
                                        segmentDataList.Add(sData);
                                    }
                                    else
                                    {
                                        List <Curve> windowCurves = GetWindowsDoorCurves(wall, sData.BoundaryCurve, transform);
                                        if (windowCurves.Count > 0)
                                        {
                                            sData.VisibleCurves.AddRange(windowCurves);
                                            sData.GetViewPoints(false);
                                            segmentDataList.Add(sData);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            sData.GetViewPoints(true);
                            segmentDataList.Add(sData);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(segmentDataList);
        }