Пример #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            IList <Reference> selection1 = uidoc.Selection.PickObjects(ObjectType.Element);     //Select 1st list
            IList <XYZ>       roomsXyz1  = selection1                                           //Room 1,2 & 3
                                           .Select(r => doc.GetElement(r.ElementId).Location)
                                           .Cast <LocationPoint>()
                                           .Select(locPoint => locPoint.Point)
                                           .ToList();

            IList <Reference> selection2 = uidoc.Selection.PickObjects(ObjectType.Element);     //Select 2nd list
            IList <XYZ>       roomsXyz2  = selection2                                           //Room 4,6 & 8
                                           .Select(r => doc.GetElement(r.ElementId).Location)
                                           .Cast <LocationPoint>()
                                           .Select(locPoint => locPoint.Point)
                                           .ToList();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Find shortest Path !");

                //IList<PathOfTravel> routeMap = PathOfTravel.CreateMapped(doc.ActiveView, roomsXyz1, roomsXyz2);
                IList <PathOfTravel> routeMultiple = PathOfTravel.CreateMultiple(doc.ActiveView, roomsXyz1, roomsXyz2);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
Пример #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;
        }