예제 #1
0
        /// <summary>
        ///  Generates paths of travel from points in one room to many target locations using the slower (one-at-a-time) method.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="room"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        private static void GeneratePathsOfTravelForOneRoomManyDoors(Document doc, ViewPlan viewPlan, Room room, List <XYZ> endPoints, ResultsSummary resultsSummary)
        {
            List <XYZ> sourcePoints = GetRoomNearCornerPoints(room);

            resultsSummary.numSourcePoints += sourcePoints.Count;

            // generate paths

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();
                IList <PathOfTravelCalculationStatus> statuses;
                IList <PathOfTravel> pathsOfTravel = PathOfTravel.CreateMapped(viewPlan, sourcePoints, endPoints, out statuses);

                foreach (PathOfTravel pOT in pathsOfTravel)
                {
                    if (pOT == null)
                    {
                        resultsSummary.numFailures++;
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                }
                t.Commit();
            }
        }
예제 #2
0
        /// <summary>
        /// Wraps all calls to PathOfTravel.Create() with multiple start/ends.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="startPoints"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        /// <param name="mapAllStartsToAllEnds"></param>
        private static void GeneratePathsOfTravel(Document doc, ViewPlan viewPlan, List <XYZ> startPoints, List <XYZ> endPoints, ResultsSummary resultsSummary, bool mapAllStartsToAllEnds)
        {
            // Performance monitoring
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();

                IList <PathOfTravelCalculationStatus> statuses;
                IList <PathOfTravel> pathsOfTravel;
                if (mapAllStartsToAllEnds)
                {
                    pathsOfTravel = PathOfTravel.CreateMapped(viewPlan, startPoints, endPoints, out statuses);
                }
                else
                {
                    pathsOfTravel = PathOfTravel.CreateMultiple(viewPlan, startPoints, endPoints, out statuses);
                }

                int i = 0;

                foreach (PathOfTravel pathOfTravel in pathsOfTravel)
                {
                    if (pathOfTravel == null)
                    {
                        resultsSummary.numFailures++;
                        resultsSummary.failuresFound.Add(statuses[i]);
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                    i++;
                }

                t.Commit();
            }
            stopwatch.Stop();
            resultsSummary.elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
        }
예제 #3
0
        /// <summary>
        /// Generates paths of travel from the center points of the room to a single door using the many to many approach.   Does not collect and display results.
        /// </summary>
        private void CreatePathsOfTravelRoomCenterpointsToSingleDoor(UIDocument uiDoc)
        {
            Document  doc      = uiDoc.Document;
            ViewPlan  viewPlan = uiDoc.ActiveView as ViewPlan;
            ElementId levelId  = viewPlan.GenLevel.Id;

            // select exit door
            Reference reference   = uiDoc.Selection.PickObject(ObjectType.Element, new DoorSelectionFilter(), "Select a target door");
            Instance  doorElement = doc.GetElement(reference) as Instance;
            Transform trf         = doorElement.GetTransform();
            XYZ       endPoint    = trf.Origin;

            // find all rooms
            FilteredElementCollector fec = new FilteredElementCollector(doc);

            fec.WherePasses(new Autodesk.Revit.DB.Architecture.RoomFilter());

            List <XYZ> startPoints = new List <XYZ>();

            foreach (Room room in fec.Cast <Room>().Where <Room>(rm => rm.Level.Id == levelId))
            {
                LocationPoint location = room.Location as LocationPoint;
                if (location == null)
                {
                    continue;
                }
                XYZ roomPoint = location.Point;
                startPoints.Add(roomPoint);
            }

            // generate paths
            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();
                IList <PathOfTravelCalculationStatus> statuses;
                PathOfTravel.CreateMapped(viewPlan, startPoints, new List <XYZ> {
                    endPoint
                }, out statuses);
                t.Commit();
            }
        }