Ejemplo n.º 1
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message, ElementSet elements)
        {
            Tracer.Listeners.Add(new
                                 System.Diagnostics.EventLogTraceListener("Application"));

            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            RebarsMarkerWnd wnd = null;

            try
            {
                // Get all the necessary particulars about partitions and
                // host marks from the repository
                Schema schema = ExtensibleStorageUtils
                                .GetSchema(UpdateRepository.SCHEMA_GUID);
                if (schema == null)
                {
                    TaskDialog.Show("Warning",
                                    "No repository exists. " +
                                    "Please generate one before proceeding with this command.");
                    return(Result.Cancelled);
                }

                // Dig up the data storage element
                Autodesk.Revit.DB.ExtensibleStorage.DataStorage ds =
                    ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME);
                if (ds == null)
                {
                    TaskDialog.Show("Warning", "No data storage element. " +
                                    "Please update the repository.");
                    return(Result.Cancelled);
                }

                // Retrieve host marks grouped by partition
                IDictionary <string, ISet <string> > partsHostMarks =
                    ExtensibleStorageUtils.GetValues(
                        schema,
                        ds,
                        UpdateRepository.FN_PARTS_HOST_MARKS);

                if (partsHostMarks.Keys.Count == 0)
                {
                    TaskDialog.Show("Warning",
                                    "No rebars to mark have been bagged.");
                    return(Result.Cancelled);
                }

                // Get hold of all assemblies grouped by host marks
                IDictionary <string, ISet <string> > hostMarksAssemblies =
                    ExtensibleStorageUtils.GetValues(
                        schema,
                        ds,
                        UpdateRepository.FN_HOST_MARKS_ASSEMBLIES);

                wnd = new RebarsMarkerWnd(partsHostMarks, hostMarksAssemblies);


                wnd.OkClicked += (sender, args) =>
                {
                    IList <FamilyInstance> filteredRebars = null;

                    if (args.Assemblies.Count == 0)
                    {
                        filteredRebars =
                            //GetRebarsNotInAssemblyByPartitionHostMark(
                            //    doc,
                            //    args.Partition,
                            //    args.HostMark);
                            RebarsUtils.GetAllRebars(
                                doc,
                                args.Partition,
                                args.HostMark)
                            .Cast <FamilyInstance>()
                            .ToList();
                    }
                    else
                    {
                        filteredRebars =
                            //GetRebarsByPartitionHostMarkAssembly(
                            //    doc,
                            //    args.Partition,
                            //    args.HostMark,
                            //    args.Assemblies.ElementAt(i));
                            RebarsUtils.GetAllRebars(
                                doc,
                                args.Partition,
                                args.HostMark,
                                args.Assemblies.ToList())
                            .Cast <FamilyInstance>()
                            .ToList();
                    }

                    Tracer.Write("The number of rebars looked up amounts to " + filteredRebars.Count);

                    // Group the rebars into three categories and mark them
                    GroupRebars(filteredRebars);
                };
                wnd.ShowDialog();

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions
                   .OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (System.Exception ex)
            {
                string errorMsg = string.Format("{0}\n{1}", ex.Message, ex.StackTrace);
                Tracer.Write(errorMsg);
                TaskDialog.Show("Exception", errorMsg);
                return(Result.Failed);
            }
            finally
            {
                if (wnd != null)
                {
                    wnd.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Add an EventLogTraceListener object
            Tracer.Listeners.Add(
                new System.Diagnostics.EventLogTraceListener("Application"));

            // Lay the hands on the active document
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // set up a timer
            Timing myTimer = new Timing();

            myTimer.StartTime();
            try
            {
                // Try retrieving partitions, host marks and assemblies from the repository (schema)
                Schema schema = ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID);
                if (schema == null)
                {
                    TaskDialog.Show("Message", "Please update the repository.");
                    return(Result.Failed);
                }
                DataStorage dataStorage =
                    ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME);

                IDictionary <string, ISet <string> > partitionHostMarks = null;
                IDictionary <string, ISet <string> > hostMarkAssemblies = null;
                try {
                    partitionHostMarks =
                        ExtensibleStorageUtils.GetValues(
                            schema,
                            dataStorage,
                            UpdateRepository.FN_PARTS_HOST_MARKS);

                    hostMarkAssemblies =
                        ExtensibleStorageUtils.GetValues(
                            schema,
                            dataStorage,
                            UpdateRepository.FN_HOST_MARKS_ASSEMBLIES);

                    if (partitionHostMarks.Count == 0 ||
                        hostMarkAssemblies.Count == 0)
                    {
                        throw new Exception("No rebars have been detected.");
                    }
                }
                catch (UpdateRepositoryException ex)
                {
                    TaskDialog.Show("Warning", ex.Message);
                    return(Result.Failed);
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Warning", ex.Message);
                    return(Result.Failed);
                }
                return(Result.Failed);
                //WndMultitableSchedule wnd =
                //new WndMultitableSchedule(partitionHostMarks, hostMarkAssemblies);

                /*wnd.OkClicked += (sender, args) =>
                 * {
                 *  ComboScheduleGenerator scheduleGenerator =
                 *      new ComboScheduleGenerator(
                 *      doc,
                 *      args.MultiTableScheduleType,
                 *      args.ParametersValues,
                 *      args.ShowTitle);
                 *
                 *  scheduleGenerator.CreateSubSchedules(doc);
                 *
                 *  if (doc.ActiveView.ViewType == ViewType.DrawingSheet)
                 *  {
                 *      scheduleGenerator.PlaceOnSheet((ViewSheet)doc.ActiveView);
                 *  }
                 * };
                 * try
                 * {
                 *  wnd.ShowDialog();
                 *  return Result.Succeeded;
                 * }
                 * catch (Exception ex)
                 * {
                 *  wnd.Close();
                 *  throw ex;
                 * }*/
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (RenameException)
            {
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Exception",
                                string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                Tracer.Write(string.Format("{0}\n{1}",
                                           ex.Message, ex.StackTrace));
                return(Result.Failed);
            }
            finally
            {
                myTimer.StopTime();
                Tracer.Write(string.Format("Time elapsed: {0}s",
                                           myTimer.Duration.TotalSeconds));
            }
        }