/// <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 info needed for the updater
            Schema schema = GetOrCreateSchema();

            // Setup formatter for the schedule, if not setup.
            if (theFormatter == null)
            {
                theFormatter         = new ScheduleFormatter();
                theFormatter.Schema  = schema;
                theFormatter.AddInId = commandData.Application.ActiveAddInId;
            }

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

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

            // Add updater to listen to further changes
            AddUpdater(theFormatter);

            return(Result.Succeeded);
        }
Example #2
0
        /// <summary>
        /// Set up the updater to watch formatted schedules
        /// </summary>
        /// <param name="application">The application</param>
        public static void SetupUpdater(UIControlledApplication application)
        {
            // Setup temporary schedule formatter
            Schema            schema    = GetOrCreateSchema();
            ScheduleFormatter formatter = new ScheduleFormatter();

            formatter.Schema  = schema;
            formatter.AddInId = application.ActiveAddInId;

            // Add updater
            AddUpdater(formatter);
        }
        /// <summary>
        /// Add the updater to watch for formatted schedule changes.
        /// </summary>
        /// <param name="formatter">The schedule formatter.</param>
        private static void AddUpdater(ScheduleFormatter formatter)
        {
            // If not registered, register the updater
            if (!UpdaterRegistry.IsUpdaterRegistered(formatter.GetUpdaterId()))
            {
                // Filter on: schedule type, and extensible storage entity of the target schema
                ElementClassFilter      classFilter = new ElementClassFilter(typeof(ViewSchedule));
                ExtensibleStorageFilter esFilter    = new ExtensibleStorageFilter(formatter.Schema.GUID);
                LogicalAndFilter        filter      = new LogicalAndFilter(classFilter, esFilter);

                // Register and add trigger for updater.
                UpdaterRegistry.RegisterUpdater(formatter);
                UpdaterRegistry.AddTrigger(formatter.GetUpdaterId(), filter, Element.GetChangeTypeAny());
            }
        }