Пример #1
0
        public List <Geometry2D> CreateDoorSegments(UIDocument currentDocument, List <FamilyInstance> doors)
        {
            List <Geometry2D> convertedDoors = new List <Geometry2D>();

            foreach (FamilyInstance currentDoor in doors)
            {
                string   doorName       = currentDoor.Name;
                Wall     pacedWall      = currentDoor.Host as Wall;
                Curve    pacedWallCurve = (pacedWall.Location as LocationCurve).Curve;
                Vector2D wallStartPoint = GeometryFactory.CreateVector2D(ConvertFeetToMeters(pacedWallCurve.GetEndPoint(0).X), ConvertFeetToMeters(pacedWallCurve.GetEndPoint(0).Y), MEASUREMENTUNITFACTOR);
                Vector2D wallEndPoint   = GeometryFactory.CreateVector2D(ConvertFeetToMeters(pacedWallCurve.GetEndPoint(1).X), ConvertFeetToMeters(pacedWallCurve.GetEndPoint(1).Y), MEASUREMENTUNITFACTOR);
                Vector2D wallDirection  = wallEndPoint.Difference(wallStartPoint).GetAsNormalized();

                double doorThickness = ConvertFeetToMeters(pacedWall.WallType.Width);
                double doorWidth     = ConvertFeetToMeters(currentDoor.Symbol.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble());

                if (doorWidth == 0)
                {
                    string familyName = currentDoor.Symbol.FamilyName;

                    if (familyName.Contains(DOUBLE_SWING_CONTENT1) || familyName.Contains(DOUBLE_SWING_CONTENT2) || familyName.Contains(DOUBLE_SWING_CONTENT3))
                    {
                        doorWidth = DEFAULT_DOUBLE_DOOR_WIDTH;
                    }
                    else
                    {
                        doorWidth = DEFAULT_SINGLE_DOOR_WIDTH;
                    }
                }

                LocationPoint doorLocationPoint   = currentDoor.Location as LocationPoint;
                XYZ           doorLocation        = doorLocationPoint.Point;
                Vector2D      doorLocation2D      = GeometryFactory.CreateVector2D(ConvertFeetToMeters(doorLocation.X), ConvertFeetToMeters(doorLocation.Y), MEASUREMENTUNITFACTOR);
                Vector2D      doorMidSegmentStart = doorLocation2D.Add(wallDirection.Multiply(doorWidth / 2));
                Vector2D      doorMidSegmentEnd   = doorLocation2D.Add(wallDirection.Negate().Multiply(doorWidth / 2));

                Vector2D  doorPacingDirection        = wallDirection.Rotate(Math.PI / 2);
                Vector2D  firstWallConnectingStart   = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2));
                Vector2D  firstWallConnectingEnd     = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                Segment2D firstWallConnectingSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { firstWallConnectingStart, firstWallConnectingEnd }, doorName);
                convertedDoors.Add(firstWallConnectingSegment);
                Vector2D  secondWallConnectingStart   = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2));
                Vector2D  secondWallConnectingEnd     = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                Segment2D secondWallConnectingSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { secondWallConnectingStart, secondWallConnectingEnd }, doorName);
                convertedDoors.Add(secondWallConnectingSegment);

                Vector2D  leftDoorSegmentStart  = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2));
                Vector2D  leftDoorSegmentEnd    = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2));
                Segment2D leftDoorSegment       = GeometryFactory.CreateSegment2D(new Vector2D[] { leftDoorSegmentStart, leftDoorSegmentEnd }, doorName);
                Vector2D  rightDoorSegmentStart = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                Vector2D  rightDoorSegmentEnd   = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                Segment2D rightDoorSegment      = GeometryFactory.CreateSegment2D(new Vector2D[] { rightDoorSegmentStart, rightDoorSegmentEnd }, doorName);

                if (currentDoor.FromRoom == null || currentDoor.ToRoom == null)
                {
                    List <Vector2D> doorAreaPoints = new List <Vector2D>();

                    if (pacedWall.Flipped)
                    {
                        leftDoorSegment.Name = null;

                        Vector2D pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2));
                        doorAreaPoints.Add(pointToAdd);
                    }
                    else
                    {
                        rightDoorSegment.Name = null;

                        Vector2D pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(DEFAULT_AREA_RADIUS / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(DEFAULT_AREA_RADIUS / 2));
                        doorAreaPoints.Add(pointToAdd);
                        pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2));
                        doorAreaPoints.Add(pointToAdd);
                    }

                    Polygon2D exitDoor = GeometryFactory.CreatePolygon2D(doorAreaPoints.ToArray(), doorName);
                    convertedDoors.Add(exitDoor);
                }
                else
                {
                    leftDoorSegment.Name  = null;
                    rightDoorSegment.Name = null;
                }

                convertedDoors.Add(leftDoorSegment);
                convertedDoors.Add(rightDoorSegment);
            }

            return(convertedDoors);
        }
Пример #2
0
        public Polygon2D GetStairAreaPolygon(UIDocument currentDocument, Stairs stair, string key)
        {
            ICollection <ElementId> allRunsIds = stair.GetStairsRuns();
            ElementId currentId = allRunsIds.ElementAt(0);

            if (key.Equals(RevitObjectManager.BASE_LEVEL_KEY))
            {
                foreach (ElementId currentBaseId in allRunsIds)
                {
                    StairsRun currentStairsRun  = currentDocument.Document.GetElement(currentBaseId) as StairsRun;
                    StairsRun selectedStairsRun = currentDocument.Document.GetElement(currentId) as StairsRun;

                    if (currentStairsRun.BaseElevation < selectedStairsRun.BaseElevation)
                    {
                        currentId = currentBaseId;
                    }
                }
            }
            else if (key.Equals(RevitObjectManager.TOP_LEVEL_KEY))
            {
                foreach (ElementId currentTopId in allRunsIds)
                {
                    StairsRun currentStairsRun  = currentDocument.Document.GetElement(currentTopId) as StairsRun;
                    StairsRun selectedStairsRun = currentDocument.Document.GetElement(currentId) as StairsRun;

                    if (currentStairsRun.TopElevation > selectedStairsRun.TopElevation)
                    {
                        currentId = currentTopId;
                    }
                }
            }

            List <Vector2D> areaNodes      = new List <Vector2D>();
            StairsRun       finalStairsRun = currentDocument.Document.GetElement(currentId) as StairsRun;
            CurveLoop       stairPath      = finalStairsRun.GetStairsPath();
            Curve           firstStairPathCurve;

            if (stairPath.Count() > 1)
            {
                if ((finalStairsRun.StairsRunStyle.Equals(StairsRunStyle.Winder) || finalStairsRun.StairsRunStyle.Equals(StairsRunStyle.Spiral)) &&
                    key.Equals(RevitObjectManager.TOP_LEVEL_KEY))
                {
                    firstStairPathCurve = stairPath.ElementAt(stairPath.Count() - 1);
                }
                else
                {
                    firstStairPathCurve = stairPath.ElementAt(0);
                }
            }
            else
            {
                firstStairPathCurve = stairPath.ElementAt(0);
            }

            double stairsRunsWidth = ConvertFeetToMeters(finalStairsRun.ActualRunWidth * STAIRS_AREA_SHRINK_FACTOR);

            if (stairsRunsWidth < DEFAULT_AREA_RADIUS)
            {
                stairsRunsWidth = DEFAULT_AREA_RADIUS;
            }

            double pathsLength = ConvertFeetToMeters(firstStairPathCurve.Length * STAIRS_AREA_SHRINK_FACTOR);

            if (pathsLength < DEFAULT_AREA_RADIUS)
            {
                pathsLength = DEFAULT_AREA_RADIUS;
            }

            Vector2D pathsStart    = GeometryFactory.CreateVector2D(ConvertFeetToMeters(firstStairPathCurve.GetEndPoint(0).X), ConvertFeetToMeters(firstStairPathCurve.GetEndPoint(0).Y), MEASUREMENTUNITFACTOR);
            Vector2D pathsEnd      = GeometryFactory.CreateVector2D(ConvertFeetToMeters(firstStairPathCurve.GetEndPoint(1).X), ConvertFeetToMeters(firstStairPathCurve.GetEndPoint(1).Y), MEASUREMENTUNITFACTOR);
            Vector2D pathDirection = pathsEnd.Difference(pathsStart);
            Vector2D pathDirectionPerpenticular = pathDirection.Rotate((-1) * Math.PI / 2).GetAsNormalized();

            Vector2D firstNode = pathsStart.Add(pathDirectionPerpenticular.Multiply(stairsRunsWidth / 2));

            areaNodes.Add(firstNode);
            Vector2D pointToAdd = firstNode.Add(pathDirection);

            areaNodes.Add(pointToAdd);
            pointToAdd = pointToAdd.Add(pathDirectionPerpenticular.Multiply((-1) * stairsRunsWidth));
            areaNodes.Add(pointToAdd);
            pointToAdd = pointToAdd.Add(pathDirection.Multiply(-1));
            areaNodes.Add(pointToAdd);
            areaNodes.Add(firstNode);

            Polygon2D areaPolygon = GeometryFactory.CreatePolygon2D(areaNodes.ToArray(), finalStairsRun.Name);

            return(areaPolygon);
        }