Exemple #1
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);
        }
Exemple #2
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);
        }