RevitLookup.Test.TestElements.SimpleSwap C# (CSharp) Method

SimpleSwap() private method

Swap any selected door with a hardwired double door.
private SimpleSwap ( ) : void
return void
        private void SimpleSwap()
        {
            FamilySymbol doubleDoorSymbol = null;

              Revit.Document docu = m_revitApp.ActiveUIDocument.Document;
              Autodesk.Revit.Creation.Document doc = docu.Create;
              Autodesk.Revit.UI.Selection.Selection sel = m_revitApp.ActiveUIDocument.Selection;
              Autodesk.Revit.Creation.Application applic = m_revitApp.Application.Create;

              // First filter out to only Door elements

              //Revit.ElementSet doorSet = Utils.Selection.FilterToCategory( m_revitApp.ActiveUIDocument.Selection.Elements,
              //                                        Revit.BuiltInCategory.OST_Doors, false, m_revitApp.ActiveUIDocument.Document );

              //if( doorSet.IsEmpty )
              //{
              //  MessageBox.Show( "No door element is currently selected" );
              //  return;
              //}

              //ICollection<ElementId> doorSet
              //  = Utils.Selection.FilterToCategory(
              //    m_revitApp.ActiveUIDocument.Selection.GetElementIds(),
              //    Revit.BuiltInCategory.OST_Doors, false, docu );

              //if( 0 == doorSet.Count )
              //{
              //  MessageBox.Show( "No door element is currently selected" );
              //  return;
              //}

              // Load the concerned door family
              FilteredElementCollector fec = new FilteredElementCollector( docu );
              ElementClassFilter elementsAreWanted = new ElementClassFilter( typeof( Family ) );
              fec.WherePasses( elementsAreWanted );
              List<Element> elements = fec.ToElements() as List<Element>;

              foreach( Element element in elements )
              {
            Family fam = element as Family;
            if( fam != null )
            {
              if( fam.Name == "Double-Glass 1" )
              {
            doubleDoorSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "72\" x 78\"" );
              }
            }
              }

              string fileName = string.Empty;
              bool success = false;

              // Load the required family

              fileName = "../Data/Platform/Imperial/Library/Architectural/Doors/Double-Glass 1.rfa";
              Family doubleDoorFamily = null;

              if( doubleDoorSymbol == null )
              {
            success = docu.LoadFamily( fileName, out doubleDoorFamily );
            doubleDoorSymbol = Utils.FamilyUtil.GetFamilySymbol( doubleDoorFamily, "72\" x 78\"" );
              }

              if( doubleDoorSymbol == null )
              {
            MessageBox.Show( "Please load Double-Glass 1 into project" );
            Utils.UserInput.LoadFamily( null, docu );
              }

              // Perform the swap.

              //Revit.ElementSet elemSet = sel.Elements; // 2015, jeremy: 'Autodesk.Revit.UI.Selection.Selection.Elements' is obsolete: 'This property is deprecated in Revit 2015. Use GetElementIds() and SetElementIds instead.'
              //System.Collections.IEnumerator iters = elemSet.GetEnumerator();

              //while( iters.MoveNext() )
              //{
              //  FamilyInstance famInst = (FamilyInstance) iters.Current;
              //  famInst.Symbol = doubleDoorSymbol;
              //}

              ICollection<ElementId> elemSet = sel.GetElementIds(); // 2016, jeremy

              foreach(ElementId id in elemSet )
              {
            FamilyInstance famInst = docu.GetElement( id ) as FamilyInstance;
            famInst.Symbol = doubleDoorSymbol;
              }
        }