Esempio n. 1
0
        public static IList <SchedulableField> GetSchedulableFields(Document document, Category category)
        {
            var transaction = new Transaction(document, "Create Key Schedule");

            transaction.Start();

            ViewSchedule schedule = null;

            try
            {
                schedule = ViewSchedule.CreateKeySchedule(document, category.Id);
            }
            catch (ArgumentException)
            {
            }

            if (schedule == null)
            {
                transaction.RollBack();
                return(null);
            }

            var schedFields = schedule.Definition.GetSchedulableFields();

            transaction.RollBack();

            return(schedFields);
        }
Esempio n. 2
0
 internal void ResetFieldFilters()
 {
     if (m_createdScheduleId == null)
     {
         return;
     }
     try
     {
         using (Transaction t = new Transaction(m_doc, "Reset Filters"))
         {
             ViewSchedule tmpSchedule =
                 m_doc.GetElement(m_createdScheduleId) as ViewSchedule;
             t.Start();
             foreach (string paramName in m_filtersValues.Keys)
             {
                 FieldFilter fieldFilter =
                     new FieldFilter(tmpSchedule, paramName);
                 fieldFilter.UpdateFilter(m_filtersValues[paramName]);
             }
             t.Commit();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// The command implementation.
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ViewSchedule viewSchedule = commandData.View as ViewSchedule;

            // Setup formatter for the schedule
            ScheduleFormatter formatter = new ScheduleFormatter();

            // Setup info needed for the updater
            Schema schema = GetOrCreateSchema();

            formatter.Schema  = schema;
            formatter.AddInId = commandData.Application.ActiveAddInId;


            using (Transaction t = new Transaction(viewSchedule.Document, "Format columns"))
            {
                t.Start();
                // Make formatting changes
                formatter.FormatScheduleColumns(viewSchedule);

                // Mark schedule to be formatted
                AddMarkerEntity(viewSchedule, schema);
                t.Commit();
            }

            // Add updater if necessary
            AddUpdater(formatter);

            return(Result.Succeeded);
        }
Esempio n. 4
0
        public void AddDataToKeys(Document document, ViewSchedule schedule, ICollection <ExcelItem> excelItems, int numRows, int numCols)
        {
            var keys     = ScheduleFacade.GetScheduleKeys(document, schedule);
            var dataRows = ColumnsToRows(excelItems, numRows);

            ScheduleFacade.AddDataToKeys(document, dataRows, keys);
        }
Esempio n. 5
0
 public void AddKeysToSchedule(Document document, ViewSchedule schedule, int count)
 {
     for (int i = 0; i < count; ++i)
     {
         ScheduleFacade.AddScheduleKey(document, schedule);
     }
 }
Esempio n. 6
0
 public void AddFieldsToSchedule(Document document, ViewSchedule schedule, IEnumerable fields)
 {
     foreach (SchedulableField field in fields)
     {
         ScheduleFacade.AddScheduleField(document, schedule, field);
     }
 }
Esempio n. 7
0
        public static void AddParameterToSchedule(ViewSchedule schedule, Parameter parameter)
        {
            try
            {
                using (var tr = new Transaction(schedule.Document))
                {
                    if (!tr.HasStarted())
                    {
                        tr.Start("Adding parameter to schedule");
                    }

                    var field = schedule.Definition.GetSchedulableFields()
                                .FirstOrDefault(f => f.ParameterId == parameter.Id);

                    schedule.Definition.AddField(field);
                    //schedule.Document.Regenerate();

                    tr.Commit();
                }
            }

            catch (Exception e)
            {
                //throw new Exception("Could not add parameter to schedule", e);
            }
        }
        private static void AddFieldsToSchedule(ViewSchedule viewSchedule, IEnumerable<Parameter> parameters)
        {
            var definition = viewSchedule.Definition;

            foreach (var parameter in parameters)
            {
                var schedulableField =
                    definition.GetSchedulableFields().FirstOrDefault(sf => sf.ParameterId == parameter.Id);

                if (schedulableField == null) continue;

                definition.AddField(schedulableField);
            }

            foreach (var fieldId in definition.GetFieldOrder())
            {
                var field = definition.GetField(fieldId);

                if (field.GetName() == "Number")
                {
                    field.SheetColumnWidth = 0.060;
                }
                else if (field.GetName() == "Text")
                {
                    field.SheetColumnWidth = 0.215;
                }
            }
        }
Esempio n. 9
0
        private int getRowColumnCount(ViewSchedule view, SectionType sectionType, bool countRows)
        {
            int ctr = 1;

            // loop over the columns of the schedule
            while (true)
            {
                try                 // GetCellText will throw an ArgumentException is the cell does not exist
                {
                    if (countRows)
                    {
                        view.GetCellText(sectionType, ctr, 1);
                    }
                    else
                    {
                        view.GetCellText(sectionType, 1, ctr);
                    }
                    ctr++;
                }
                catch (Autodesk.Revit.Exceptions.ArgumentException)
                {
                    return(ctr);
                }
            }
        }
Esempio n. 10
0
        protected bool IsSheetList(ViewSchedule schedule)
        {
            try
            {
                if (Sheets.Length == 0)
                {
                    return(false);
                }

                var definition = schedule.Definition;
                foreach (var fieldId in definition.GetFieldOrder())
                {
                    var field     = definition.GetField(fieldId);
                    var parameter = GetParameter(field);
                    if (IsSheetNumberParameter(parameter))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Error", ex.Message);
            }
            return(false);
        }
        public MainWindow(UIDocument _uidoc, ViewSchedule _viewSched)
        {
            InitializeComponent();

            uidoc     = _uidoc;
            doc       = uidoc.Document;
            viewSched = _viewSched;

            // Placeholder sheets print as blank pages, we don't want them
            sheetList = new FilteredElementCollector(doc);
            sheetList.OfClass(typeof(ViewSheet))
            .Cast <ViewSheet>()
            .Where <ViewSheet>(i => !i.IsPlaceholder);


            viewSet = new ViewSet();

            // Read the data from the schedule
            TableData        table   = viewSched.GetTableData();
            TableSectionData section = table.GetSectionData(SectionType.Body);

            nRows           = section.NumberOfRows;
            nCols           = section.NumberOfColumns;
            SetNameBox.Text = viewSched.Name;

            // This is to select which column the sheet numbers are
            foreach (int num in Enumerable.Range(1, nCols))
            {
                Cbx.Items.Add(num);
            }
            Cbx.SelectedIndex = 0;
        }
Esempio n. 12
0
        public static ViewSchedule Create(Document doc, BuiltInCategory elementType, string schName)
        {
            ViewSchedule schedule      = null;
            var          canBeModified = doc.IsModifiable;
            var          isReadonly    = doc.IsReadOnly;

            if (!canBeModified && isReadonly)
            {
                throw new CancellableException("The document has an open transaction somewhere");
            }

            using (var trans = new Transaction(doc, $"Creating new {elementType.GetType().Name} schedule"))
            {
                var opts = trans.GetFailureHandlingOptions();
                opts.SetDelayedMiniWarnings(true);

                if (!trans.HasStarted())
                {
                    trans.Start();
                }

                schedule      = ViewSchedule.CreateSchedule(doc, new ElementId(elementType), ElementId.InvalidElementId);
                schedule.Name = schName;

                trans.Commit(opts);
            }

            return(schedule);
        }
        /***********************************************************************************************************************/


        private static void SetGraphics(ViewSchedule schedule)
        {
#if REVIT_2016
            schedule.Definition.ShowTitle = false;
            schedule.Definition.ShowHeaders = false;
#endif
        }
Esempio n. 14
0
 internal void RenameSchedule(bool showTitle)
 {
     ++m_counter;
     using (Transaction t = new Transaction(m_doc, "Rename Schedule"))
     {
         ViewSchedule tmpSchedule =
             m_doc.GetElement(m_createdScheduleId) as ViewSchedule;
         string newName = GenerateName(tmpSchedule.ViewName);
         try
         {
             t.Start();
             tmpSchedule.ViewName = newName;
             // Find the shared parameter utilized for grouping
             // schedules in the schedule browser and set it
             // to a particualr value
             tmpSchedule.LookupParameter(RebarsUtils.PARTITION)
             .Set(m_filtersValues[RebarsUtils.PARTITION]);
             // If this is the first schedule and
             // Show Title is ticked, then
             // make the title visible
             if (m_counter == 1 && showTitle)
             {
                 tmpSchedule.Definition.ShowTitle = true;
                 try
                 {
                     if (m_scheduleType == ScheduleType.AssemblySchedule)
                     {
                         ChangeTitle(tmpSchedule, m_filtersValues[RebarsUtils.ASSEMBLY_MARK]);
                     }
                 }
                 catch (Exception ex)
                 {
                     Autodesk.Revit.UI.TaskDialog.Show("Exception", $"{ex.Message}\n{ex.StackTrace}.");
                 }
             }
             else
             {
                 tmpSchedule.Definition.ShowTitle = false;
             }
         }
         catch (Exception)
         {
             if (t.GetStatus() == TransactionStatus.Started)
             {
                 t.RollBack();
             }
             Autodesk.Revit.UI.TaskDialog.Show("Exception", $"{newName} already exists.");
             using (Transaction tt = new Transaction(m_doc, "Clean up"))
             {
                 tt.Start();
                 m_doc.Delete(ScheduleId);
                 tt.Commit();
             }
             m_createdScheduleId = null;
             throw new RenameException();
         }
         t.Commit();
     }
 }
        public int GetLastRowNumber(ViewSchedule schedule)
        {
            TableData        calTabledata = schedule.GetTableData();
            TableSectionData tsd          = calTabledata.GetSectionData(SectionType.Body);
            int lastRowNumber             = tsd.LastRowNumber;

            return(lastRowNumber);
        }
Esempio n. 16
0
        internal void DuplicateSchedules(Subschedule template)
        {
            ViewSchedule vs = m_doc.GetElement(template.Id)
                              as ViewSchedule;

            template.Id =
                vs.Duplicate(ViewDuplicateOption.Duplicate);
        }
Esempio n. 17
0
        private static Result createReshoringLayoutSheets(UIDocument uiDoc)
        {
            Document _doc = uiDoc.Document;

            string _titleblockName           = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            XYZ    _columnScheduleBottomLeft = new XYZ(2.3354130772204, 2.39482128194158, 0);
            XYZ    _viewCenter = new XYZ(1.45453036348288, 1.18116967618813, 0.871414246948733);
            XYZ    _levelScheduleBottomLeft = new XYZ(0.156336990263879, 2.37688649933288, 0);

            var _levels = Getters.GetLevels(_doc);

            Level _levelAbove  = null;
            Level _topLevel    = _levels.FirstOrDefault();
            Level _bottomLevel = _levels.LastOrDefault();

            List <Tuple <ViewSheet, View> > _sheetsWithViews = new List <Tuple <ViewSheet, View> >();


            foreach (Level _level in _levels)
            {
                if (_levelAbove == null)
                {
                    _levelAbove = _level;
                }

                BoundedViewCreator _boundedViewCreator = new BoundedViewCreator(_level, null, null);
                SheetCreator       _sheetCreator       = new SheetCreator(_doc);
                string             _viewName           = _boundedViewCreator.GetViewName(string.Empty, "FP");
                ViewSheet          _viewSheet          = _sheetCreator.CreateSheet(_titleblockName, _viewName, _viewName);
                ViewPlan           _viewPlan           = _boundedViewCreator.CreateViewPlan(80);
                _sheetsWithViews.Add(new Tuple <ViewSheet, View>(_viewSheet, _viewPlan));

                ViewSchedule          _columnSchedule = ScheduleCreator.CreateLayoutColumnSchedule(_doc, _level.Name, " Reshores");
                ScheduleSheetInstance _columnScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _columnSchedule.Id, _columnScheduleBottomLeft);

                ViewSchedule          _levelSchedule = ScheduleCreator.CreateLayoutLoadSchedule(_doc, _level.Name, " Loads");
                ScheduleSheetInstance _levelScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _levelSchedule.Id, _levelScheduleBottomLeft);

                _levelAbove = _level;
            }

            _doc.Regenerate();

            FamilySymbol _tagSymbol = new FilteredElementCollector(_doc)
                                      .OfCategory(BuiltInCategory.OST_MultiCategoryTags)
                                      .OfClass(typeof(FamilySymbol)).OfType <FamilySymbol>()
                                      .FirstOrDefault(p => p.FamilyName.Contains("Mark"));


            foreach (var _sheetWithView in _sheetsWithViews)
            {
                DimensionCreator.CreateDimensions(_sheetWithView.Item2);
                TagCreator.CreateTags(_sheetWithView.Item2, _tagSymbol);
                Viewport.Create(_doc, _sheetWithView.Item1.Id, _sheetWithView.Item2.Id, _viewCenter);
            }

            return(Result.Succeeded);
        }
Esempio n. 18
0
 /// <summary>
 /// Implements IUpdater.Execute()
 /// </summary>
 /// <param name="data"></param>
 public void Execute(UpdaterData data)
 {
     // Only previously formatted schedules should trigger - so just reformat them
     foreach (ElementId scheduleId in data.GetModifiedElementIds())
     {
         ViewSchedule schedule = data.GetDocument().GetElement(scheduleId) as ViewSchedule;
         FormatScheduleColumns(schedule);
     }
 }
        //public QLViewScheduleResolve(ViewSchedule aViewSchedule, Field queryFieldForViewScheduleData)
        //{
        //    id = aViewSchedule.Id.ToString();
        //    name = aViewSchedule.Name;

        //    if (queryFieldForViewScheduleData != null)
        //    {
        //        try
        //        {
        //            qlViewScheduleData = ResolverEntry.aRevitTask.Run<QLViewScheduleData>(app =>
        //            {
        //                ////https://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html
        //                TableData table = aViewSchedule.GetTableData();
        //                var rowCount = aViewSchedule.GetTableData().GetSectionData(SectionType.Body).NumberOfRows;
        //                var colCount = aViewSchedule.GetTableData().GetSectionData(SectionType.Body).NumberOfColumns;

        //                QLViewScheduleData data = new QLViewScheduleData();
        //                data.headers = new List<string>();
        //                data.rows = new List<QLViewScheduleRow>();

        //                for (int i = 0; i < rowCount; i++)
        //                {
        //                    QLViewScheduleRow newRow = new QLViewScheduleRow();
        //                    newRow.id = i.ToString();
        //                    newRow.cells = new List<string>();
        //                    for (int j = 0; j < colCount; j++)
        //                    {
        //                        var cellString = aViewSchedule.GetCellText(SectionType.Body, i, j);
        //                        if (i == 0)
        //                        {
        //                            data.headers.Add(cellString);
        //                        }
        //                        else
        //                        {
        //                            newRow.cells.Add(cellString);
        //                        }
        //                    }
        //                    if (i == 0)
        //                    {
        //                        i++; // skip 2nd row - it's always blank
        //                    }
        //                    else
        //                    {
        //                        data.rows.Add(newRow);
        //                    }
        //                }
        //                return data;
        //            }).Result;
        //        }
        //        catch (Exception ex)
        //        {
        //            var m = ex.Message;
        //        }
        //    }
        //}
        public QLViewScheduleResolve(ViewSchedule aViewSchedule, object aFieldOrContext)
        {
            id   = aViewSchedule.Id.ToString();
            name = aViewSchedule.Name;

            var queryFieldForViewScheduleData = GraphQlHelpers.GetFieldFromFieldOrContext(aFieldOrContext, "qlViewScheduleData");

            if (queryFieldForViewScheduleData != null)
            {
                try
                {
                    qlViewScheduleData = ResolverEntry.aRevitTask.Run <QLViewScheduleData>(app =>
                    {
                        ////https://thebuildingcoder.typepad.com/blog/2012/05/the-schedule-api-and-access-to-schedule-data.html
                        TableData table = aViewSchedule.GetTableData();
                        var rowCount    = aViewSchedule.GetTableData().GetSectionData(SectionType.Body).NumberOfRows;
                        var colCount    = aViewSchedule.GetTableData().GetSectionData(SectionType.Body).NumberOfColumns;

                        QLViewScheduleData data = new QLViewScheduleData();
                        data.headers            = new List <string>();
                        data.rows = new List <QLViewScheduleRow>();

                        for (int i = 0; i < rowCount; i++)
                        {
                            QLViewScheduleRow newRow = new QLViewScheduleRow();
                            newRow.id    = i.ToString();
                            newRow.cells = new List <string>();
                            for (int j = 0; j < colCount; j++)
                            {
                                var cellString = aViewSchedule.GetCellText(SectionType.Body, i, j);
                                if (i == 0)
                                {
                                    data.headers.Add(cellString);
                                }
                                else
                                {
                                    newRow.cells.Add(cellString);
                                }
                            }
                            if (i == 0)
                            {
                                i++; // skip 2nd row - it's always blank
                            }
                            else
                            {
                                data.rows.Add(newRow);
                            }
                        }
                        return(data);
                    }).Result;
                }
                catch (Exception ex)
                {
                    var m = ex.Message;
                }
            }
        }
Esempio n. 20
0
        public static List <Element> GetScheduleKeys(Document document, ViewSchedule schedule)
        {
            var collector = new FilteredElementCollector(document);
            var keys      = collector
                            .WhereElementIsNotElementType()
                            .Where(x => x.OwnerViewId == schedule.Id).ToList();

            return(keys);
        }
Esempio n. 21
0
 public ReorderOptions(ViewSchedule schedule, ViewSheet[] sortedSheets, ViewSheet[] unsortedSheets, ColumnEntry inclusionColumn, ColumnEntry sortColumn, string pdfFileName)
 {
     this.InclusionColumn = inclusionColumn;
     this.Schedule        = schedule;
     this.SortedSheets    = sortedSheets;
     this.SortColumn      = sortColumn;
     this.PdfFileName     = pdfFileName;
     this.UnsortedSheets  = unsortedSheets;
 }
Esempio n. 22
0
        private void HideEmptyColumns(ElementId id)
        {
            if (id == ElementId.InvalidElementId)
            {
                return;
            }

            ViewSchedule viewSchd = m_doc.GetElement(id)
                                    as ViewSchedule;
            ScheduleDefinition schdDef   = viewSchd.Definition;
            TableSectionData   tableData =
                viewSchd.GetTableData().GetSectionData(SectionType.Body);

            Func <ScheduleFieldId, bool> filterHiddenFields = delegate(ScheduleFieldId fId)
            {
                if (schdDef.GetField(fId).IsHidden)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            IList <ScheduleFieldId> visibleFields = schdDef
                                                    .GetFieldOrder()
                                                    .Where(filterHiddenFields)
                                                    .ToList();

            StringBuilder strBld = new StringBuilder();

            for (int i = tableData.FirstColumnNumber + 2; i <= tableData.LastColumnNumber; ++i)
            {
                double sum = 0;

                for (int j = tableData.FirstRowNumber + 1; j <= tableData.LastRowNumber; ++j)
                {
                    string cellContent = tableData.GetCellText(j, i);
                    strBld.AppendFormat("({0}, {1}) = {2}\n", i, j, cellContent);
                    double cellValue;
                    if (Double.TryParse(cellContent, out cellValue))
                    {
                        sum += cellValue;
                    }
                }

                // if the current column holds no value, then have it hidden
                if (sum == 0)
                {
                    ScheduleField field = schdDef.GetField(visibleFields[i]);
                    field.IsHidden = true;
                }
            }
            System.Diagnostics.Trace.Write(strBld.ToString());
        }
Esempio n. 23
0
        public ActionResult ViewSchedules()
        {
            var schedule = _context.Schedules;
            var view     = new ViewSchedule
            {
                ListSchedule = schedule.ToList()
            };

            return(View(view));
        }
 public static void AddParameterToSchedule(ViewSchedule schedule, params Parameter[] parameters)
 {
     foreach (var p in parameters)
     {
         if (!schedule.HasParameter(p))
         {
             AddParameterToSchedule(schedule, p);
         }
     }
 }
Esempio n. 25
0
        internal void ShowTitle(Subschedule template)
        {
            ViewSchedule vs = m_doc.GetElement(template.Id)
                              as ViewSchedule;

            if (template.ShowTitle)
            {
                vs.Definition.ShowTitle = true;
            }
        }
Esempio n. 26
0
        public ActionResult ResultSearch()
        {
            var v         = _context.Schedules.ToList();
            var viewmodel = new ViewSchedule
            {
                ListSchedule = v
            };

            return(View());
        }
        public static void CreateWallsSchedule(UIDocument uidoc)
        {
            Document doc = uidoc.Document;

            using (Transaction t = new Transaction(doc, "Create Schedule"))
            {
                t.Start();

                // Создание спецификации для стен
                ViewSchedule wallsSchedule =
                    ViewSchedule.CreateSchedule(doc,
                                                new ElementId(BuiltInCategory.OST_Walls));

                // Добавление полей в спецификацию
                foreach (SchedulableField schedulableFields
                         in GetSchedulableFields(doc))
                {
                    wallsSchedule.Definition.AddField(schedulableFields);
                }

                // Назначение стадии
                SetPhaseByName(wallsSchedule, "KR-3");

                // Для каждого экземпляра = false
                wallsSchedule.Definition.IsItemized = false;

                // Вычесление итогов
                wallsSchedule.Definition.GetField(0).DisplayType =
                    ScheduleFieldDisplayType.Totals;
                wallsSchedule.Definition.GetField(1).DisplayType =
                    ScheduleFieldDisplayType.Totals;

                // Назначение ширины столбцам
                wallsSchedule.Definition.GetField(0).GridColumnWidth = 30 * mmToft;
                wallsSchedule.Definition.GetField(1).GridColumnWidth = 30 * mmToft;
                wallsSchedule.Definition.GetField(2).GridColumnWidth = 55 * mmToft;

                // Назначение выравнивания
                wallsSchedule.Definition.GetField(1).HorizontalAlignment =
                    ScheduleHorizontalAlignment.Right;
                wallsSchedule.Definition.GetField(2).HorizontalAlignment =
                    ScheduleHorizontalAlignment.Center;

                // Установка сортировки/групировки
                ScheduleSortGroupField sortGroupField =
                    new ScheduleSortGroupField(
                        wallsSchedule.Definition.GetField(2).FieldId,
                        ScheduleSortOrder.Ascending);
                wallsSchedule.Definition.AddSortGroupField(sortGroupField);

                t.Commit();
                uidoc.ActiveView = wallsSchedule;
            }
        }
        internal ScheduleSortGroupField AppendGroupField(ViewSchedule _viewSchedule, ScheduleField field)
        {
            ScheduleSortGroupField _sortGroupField = new ScheduleSortGroupField(field.FieldId);

            _sortGroupField.ShowHeader    = false;
            _sortGroupField.SortOrder     = ScheduleSortOrder.Descending;
            _sortGroupField.ShowBlankLine = false;

            _viewSchedule.Definition.AddSortGroupField(_sortGroupField);
            return(_sortGroupField);
        }
Esempio n. 29
0
        public static ElementId getSelectedFamily(UIDocument uidoc)
        {
            Document doc = uidoc.Document;

            //Get first ElementId of a Note Block family.
            ICollection <ElementId> noteblockFamilies = ViewSchedule.GetValidFamiliesForNoteBlock(doc);

            ElementId symbolId = noteblockFamilies.First <ElementId>();

            return(symbolId);
        }
Esempio n. 30
0
        public static void HideField(Document document, ViewSchedule schedule, int fieldIndex)
        {
            var transaction = new Transaction(document, "Add Field");

            transaction.Start();

            var field = schedule.Definition.GetField(fieldIndex);

            field.IsHidden = true;

            transaction.Commit();
        }
Esempio n. 31
0
        public static ViewSchedule GetNewSchedule(Document document, ElementId category)
        {
            var transaction = new Transaction(document, "Create Key Schedule");

            transaction.Start();

            var schedule = ViewSchedule.CreateKeySchedule(document, category);

            transaction.Commit();

            return(schedule);
        }
        /// <summary>
        /// Adds an entity to the schedule, indicating that the schedule should be formatted by this tool.
        /// </summary>
        /// <param name="viewSchedule">The schedule.</param>
        /// <param name="schema">The schema used for the entity.</param>
        private void AddMarkerEntity(ViewSchedule viewSchedule, Schema schema)
        {
            // Is entity already present?
            Entity entity = viewSchedule.GetEntity(schema);

            // If not, add it.
            if (!entity.IsValid())
            {
                entity = new Entity(schema);
                entity.Set <bool>("Formatted", true);
                viewSchedule.SetEntity(entity);
            }
        }
        private static void AddFilterToSchedule(ViewSchedule schedule, IEnumerable<Parameter> parameters, string filterValue, string paramName)
        {
            var definition = schedule.Definition;
            var seriesField = FindField(schedule, parameters.FirstOrDefault(p => p.Definition.Name == paramName));

            if (null == seriesField)
            {
                seriesField = definition.AddField(ScheduleFieldType.Instance, new ElementId(BuiltInParameter.ROOM_LEVEL_ID));
            }

            seriesField.IsHidden = true;
            var filter = new ScheduleFilter(seriesField.FieldId, ScheduleFilterType.Equal, filterValue);
            definition.AddFilter(filter);
        }
        private static void AddGroupingToSchedule(ViewSchedule schedule, IEnumerable<Parameter> parameters, string paramName)
        {
            var field = FindField(schedule, parameters.FirstOrDefault(p => p.Definition.Name == paramName));

            if (field == null) throw new Exception("Unable to find field.");

            var sortGroupField = new ScheduleSortGroupField(field.FieldId, ScheduleSortOrder.Ascending);

            schedule.Definition.AddSortGroupField(sortGroupField);
            schedule.Definition.IsItemized = false;
        }
        private static ScheduleField FindField(ViewSchedule schedule, Parameter param)
        {
            var definition = schedule.Definition;
            var paramId = param.Id;

            return 
                definition.GetFieldOrder()
                    .Select(fieldId => definition.GetField(fieldId))
                    .FirstOrDefault(foundField => foundField.ParameterId == paramId);
        }