/// <summary>
        /// run this sample now
        /// </summary>
        public void Run()
        {
            try
            {
                // filtrate the windows from the element set.

                ElementClassFilter       filter1     = new ElementClassFilter(typeof(FamilyInstance));
                ElementCategoryFilter    filter2     = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
                LogicalAndFilter         andFilter   = new LogicalAndFilter(filter1, filter2);
                FilteredElementCollector collector   = new FilteredElementCollector(m_doc);
                ICollection <Element>    arrayFamily = collector.WherePasses(andFilter).ToElements();

                // filtrate the Symbol from the element set to modify the window's type.


                ElementClassFilter    filter3    = new ElementClassFilter(typeof(FamilySymbol));
                ElementCategoryFilter filter4    = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
                LogicalAndFilter      andFilter1 = new LogicalAndFilter(filter3, filter4);
                collector = new FilteredElementCollector(m_doc);
                ICollection <Element> found       = collector.WherePasses(andFilter1).ToElements();
                ElementArray          arraySymbol = new ElementArray();
                foreach (Element ee in found)
                {
                    if (ee.Name == "36\" x 72\"")
                    {
                        arraySymbol.Insert(ee, 0);
                        break;
                    }
                }

                MessageBox.Show("Replace 16\" x 24\" to 36\" x 72\".", "FindAndReplaceWinType");
                // matching and replacing
                int replacenum = 0;
                foreach (Element ee in arrayFamily)
                {
                    FamilyInstance windows = ee as FamilyInstance;
                    if (0 == windows.Symbol.Name.CompareTo("16\" x 24\""))
                    {
                        windows.Symbol = arraySymbol.get_Item(0) as FamilySymbol;
                        replacenum++;
                    }
                }
                // Show the number of windows modified.
                MessageBox.Show("Revit has completed its search and has made " + replacenum + " modifications.", "FindAndReplaceWinType");
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Inserts a new element definition at index
 /// </summary>
 /// <param name="index">Index at which the new definition will be inserted at</param>
 public void Insert(int index)
 {
     AddPreprocess(); elements.Insert(index, kState.NewInstance(this) as T);
     OnPropertyChanged("Elements");
 }
 /// <summary>
 /// Inserts a new element definition at index
 /// </summary>
 /// <param name="index">Index at which the new definition will be inserted at</param>
 public void Insert(int index)
 {
     AddPreprocess(); elements.Insert(index, kState.NewInstance(this) as T);
 }