This class used to represents data for one API filter. It consists of BuiltInCategory and filter rules
        /// <summary>
        /// Initialize filter data with existing view filters
        /// </summary>
        void InitializeFilterData()
        {
            // Get all existing filters
            ICollection <ParameterFilterElement> filters = FiltersUtil.GetViewFilters(m_doc);

            foreach (ParameterFilterElement filter in filters)
            {
                // Get all data of the current filter and create my FilterData
                ICollection <ElementId> catIds = filter.GetCategories();

                // Get the ElementFilter representing the set of FilterRules.
                ElementFilter elemFilter = filter.GetElementFilter();
                // Check that the ElementFilter represents a conjunction of ElementFilters.
                // We will then check that each child ElementFilter contains just one FilterRule.
                IList <FilterRule> filterRules = FiltersUtil.GetConjunctionOfFilterRulesFromElementFilter(elemFilter);
                int numFilterRules             = filterRules.Count;
                if (0 == numFilterRules)
                {
                    return; // Error
                }
                // Create filter rule data now
                List <FilterRuleBuilder> ruleDataSet = new List <FilterRuleBuilder>();
                foreach (FilterRule filterRule in filterRules)
                {
                    ElementId         paramId          = filterRule.GetRuleParameter();
                    int               parameterIdAsInt = paramId.IntegerValue;
                    BuiltInParameter  bip      = (BuiltInParameter)parameterIdAsInt;
                    FilterRuleBuilder ruleData = FiltersUtil.CreateFilterRuleBuilder(bip, filterRule);
                    ruleDataSet.Add(ruleData);
                }

                //
                // Create Filter data
                FilterData filterData = new FilterData(m_doc, catIds, ruleDataSet);
                m_dictFilters.Add(filter.Name, filterData);
                //
                // also add to control
                filtersListBox.Items.Add(filter.Name);
            }
        }
        /// <summary>
        /// Create new filter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newButton_Click(object sender, EventArgs e)
        {
            // Show new name for filter, unique name is required for creating filters
            List <String> inUseKeys = new List <string>();

            inUseKeys.AddRange(m_dictFilters.Keys);
            NewFilterForm newForm = new NewFilterForm(inUseKeys);
            DialogResult  result  = newForm.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }
            //
            // Create new filter data now(the filter data will be reflected to Revit filter when Ok button is clicked).
            String newFilterName = newForm.FilterName;

            m_currentFilterData = new FilterData(m_doc, new List <BuiltInCategory>(), new List <FilterRuleBuilder>());
            m_dictFilters.Add(newFilterName, m_currentFilterData);
            filtersListBox.Items.Add(newFilterName);
            filtersListBox.SetSelected(filtersListBox.Items.Count - 1, true);
            ResetControls_HasFilter();
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize filter data with existing view filters
        /// </summary>
        void InitializeFilterData()
        {
            // Get all existing filters
            ICollection <ParameterFilterElement> filters = FiltersUtil.GetViewFilters(m_doc);

            foreach (ParameterFilterElement filter in filters)
            {
                // get all data of current filter and create my FilterData
                ICollection <ElementId>  catIds   = filter.GetCategories();
                ICollection <ElementId>  paramIds = filter.GetRuleParameters();
                ICollection <FilterRule> rules    = filter.GetRules();
                if (paramIds.Count != rules.Count)
                {
                    return;
                }
                //
                // create filter rule data now
                List <FilterRuleBuilder> ruleDataSet = new List <FilterRuleBuilder>();
                IEnumerator <ElementId>  paramIter   = paramIds.GetEnumerator();
                paramIter.Reset();
                foreach (FilterRule rule in rules)
                {
                    paramIter.MoveNext();
                    FilterRuleBuilder ruleData = FiltersUtil.CreateFilterRuleBuilder(
                        (BuiltInParameter)paramIter.Current.IntegerValue, rule);
                    ruleDataSet.Add(ruleData);
                }
                //
                // Create Filter data
                FilterData filterData = new FilterData(m_doc, catIds, ruleDataSet);
                m_dictFilters.Add(filter.Name, filterData);
                //
                // also add to control
                filtersListBox.Items.Add(filter.Name);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Create new filter 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void newButton_Click(object sender, EventArgs e)
 {
     // Show new name for filter, unique name is required for creating filters
     List<String> inUseKeys = new List<string>();
     inUseKeys.AddRange(m_dictFilters.Keys);
     NewFilterForm newForm = new NewFilterForm(inUseKeys);
     DialogResult result = newForm.ShowDialog();
     if (result != DialogResult.OK)
         return;
     //
     // Create new filter data now(the filter data will be reflected to Revit filter when Ok button is clicked).
     String newFilterName = newForm.FilterName;
     m_currentFilterData = new FilterData(m_doc, new List<BuiltInCategory>(), new List<FilterRuleBuilder>());
     m_dictFilters.Add(newFilterName, m_currentFilterData);
     filtersListBox.Items.Add(newFilterName);
     filtersListBox.SetSelected(filtersListBox.Items.Count - 1, true);
     ResetControls_HasFilter();
 }
Esempio n. 5
0
 /// <summary>
 /// Initialize filter data with existing view filters
 /// </summary>
 void InitializeFilterData()
 {
     // Get all existing filters
     ICollection<ParameterFilterElement> filters = FiltersUtil.GetViewFilters(m_doc);
     foreach (ParameterFilterElement filter in filters)
     {
         // get all data of current filter and create my FilterData
         ICollection<ElementId> catIds = filter.GetCategories();
         ICollection<ElementId> paramIds = filter.GetRuleParameters();
         ICollection<FilterRule> rules = filter.GetRules();
         if (paramIds.Count != rules.Count)
             return;
         //
         // create filter rule data now
         List<FilterRuleBuilder> ruleDataSet = new List<FilterRuleBuilder>();
         IEnumerator<ElementId> paramIter = paramIds.GetEnumerator();
         paramIter.Reset();
         foreach (FilterRule rule in rules)
         {
             paramIter.MoveNext();
             FilterRuleBuilder ruleData = FiltersUtil.CreateFilterRuleBuilder(
                 (BuiltInParameter)paramIter.Current.IntegerValue, rule);
             ruleDataSet.Add(ruleData);
         }
         //
         // Create Filter data
         FilterData filterData = new FilterData(m_doc, catIds, ruleDataSet);
         m_dictFilters.Add(filter.Name, filterData);
         //
         // also add to control
         filtersListBox.Items.Add(filter.Name);
     }
 }