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

ClassRoom() public method

public ClassRoom ( ) : void
return void
        public void ClassRoom()
        {
            Revit.Document doc = m_revitApp.ActiveUIDocument.Document;

              // get the symbols in the beginning itself , so that
              // if one is missing you can load it
              FamilySymbol columnSymbol = null;
              FamilySymbol chairSymbol = null;
              FamilySymbol deskSymbol = null;
              FamilySymbol chairMainSymbol = null;
              //FamilySymbol chairSym = null;
              FamilySymbol doorSymbol = null;
              Family columnfamily;
              Family deskfamily;
              Family doorfamily;

              FilteredElementCollector fec = new FilteredElementCollector( m_revitApp.ActiveUIDocument.Document );
              ElementClassFilter familiesAreWanted = new ElementClassFilter( typeof( Family ) );
              fec.WherePasses( familiesAreWanted );
              List<Element> elements = fec.ToElements() as List<Element>;

              foreach( Element element in elements )
              {
            Family fam = element as Family;
            if( fam != null )
            {
              if( fam.Name == "Rectangular Column" )
              {
            columnSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "24\" x 24\"" );
              }

              if( fam.Name == "Desk" )
              {
            deskSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "60\" x 30\"" );
              }

              if( fam.Name == "Single-Flush" )
              {
            doorSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "36\" x 84\"" );
              }

              if( fam.Name == "Chair-Tablet Arm" )
              {
            chairSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "Chair-Tablet" );
              }

              if( fam.Name == "Chair-Breuer" )
              {
            chairMainSymbol = Utils.FamilyUtil.GetFamilySymbol( fam, "Chair-Breuer" );
              }
            }
              }

              String familyNameToLoad = "";

              // check for required families
              if( columnSymbol == null )
              {
            MessageBox.Show( "Please load Rectangular Column 24\" x 24\" into project" );

            String famName = Utils.UserInput.GetFamilyNameFromUser( null, ref familyNameToLoad );

            m_revitApp.ActiveUIDocument.Document.LoadFamily( famName, out columnfamily );
            if( columnfamily != null )
            {
              columnSymbol = Utils.FamilyUtil.GetFamilySymbol( columnfamily, "24\" x 24\"" );
            }
              }

              if( deskSymbol == null )
              {
            MessageBox.Show( "Please load Desk 60\" x 30\" into project" );

            String famName = Utils.UserInput.GetFamilyNameFromUser( null, ref familyNameToLoad );

            m_revitApp.ActiveUIDocument.Document.LoadFamily( famName, out deskfamily );
            if( deskfamily != null )
            {
              deskSymbol = Utils.FamilyUtil.GetFamilySymbol( deskfamily, "36\" x 84\"" );
            }
              }

              if( doorSymbol == null )
              {
            MessageBox.Show( "Please load door Single Flush 36\" x 84\" into project" );

            String famName = Utils.UserInput.GetFamilyNameFromUser( null, ref familyNameToLoad );

            m_revitApp.ActiveUIDocument.Document.LoadFamily( famName, out doorfamily );
            if( doorfamily != null )
            {
              doorSymbol = Utils.FamilyUtil.GetFamilySymbol( doorfamily, "36\" x 84\"" );
            }
              }

              IDictionary<String, String> libsPaths = m_revitApp.Application.GetLibraryPaths();
              string pathName = string.Empty;
              foreach( KeyValuePair<String, String> libPath in libsPaths )
              {
            pathName = libPath.Value;
            break;
              }

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

              fileName = pathName + @"\Furniture\Chair-Tablet Arm.rfa";

              //Boolean load = m_revitApp.ActiveUIDocument.Document.LoadFamilySymbol(fileName, "Chair-Tablet Arm", ref chairSym);

              Family chairFamily;
              // if not found in doc try to load automatically
              if( chairSymbol == null )
              {
            success = m_revitApp.ActiveUIDocument.Document.LoadFamily( fileName, out chairFamily );
            chairSymbol = Utils.FamilyUtil.GetFamilySymbol( chairFamily, "Chair-Tablet Arm" );
              }
              // last ditch effort by trying to load manually
              if( chairSymbol == null )
              {
            MessageBox.Show( "Please load Chair-Tablet Arm into project" );
            Utils.UserInput.LoadFamily( null, m_revitApp.ActiveUIDocument.Document );
              }

              fileName = pathName + @"\Furniture\Chair-Breuer.rfa";
              Family chairMainFamily;
              // if not found in doc try to load automatically
              if( chairMainSymbol == null )
              {
            success = m_revitApp.ActiveUIDocument.Document.LoadFamily( fileName, out chairMainFamily );
            chairMainSymbol = Utils.FamilyUtil.GetFamilySymbol( chairMainFamily, "Chair-Breuer" );
              }
              // last ditch effort by trying to load manually
              if( chairMainSymbol == null )
              {
            MessageBox.Show( "Please load Chair-Breuer into project" );
            Utils.UserInput.LoadFamily( null, m_revitApp.ActiveUIDocument.Document );
              }

              // get the level on which we want to build
              Level level1 = null;
              FilteredElementCollector levelFec = new FilteredElementCollector( doc );
              ElementClassFilter levelsAreWanted = new ElementClassFilter( typeof( Level ) );
              levelFec.WherePasses( levelsAreWanted );
              List<Element> levels = levelFec.ToElements() as List<Element>;

              foreach( Element element in levels )
              {
            Level levelTemp = element as Level;
            if( levelTemp != null )
            {
              if( levelTemp.Name == "Level 1" )
              {
            level1 = levelTemp;
            break;
              }
            }
              }

              // draw 4 lines
              XYZ startPt1 = new XYZ( 0.0, 0.0, 0.0 );
              XYZ endPt1 = new XYZ( 56.5, 0.0, 0.0 );
              Line line1 = Line.CreateBound( startPt1, endPt1 );

              XYZ startPt2 = endPt1;
              XYZ endPt2 = new XYZ( 56.5, 61.5, 0.0 );
              Line line2 = Line.CreateBound( startPt2, endPt2 );

              XYZ startPt3 = endPt2;
              XYZ endPt3 = new XYZ( 0.0, 61.5, 0.0 );
              Line line3 = Line.CreateBound( startPt3, endPt3 );

              XYZ startPt4 = endPt3;
              XYZ endPt4 = startPt1;
              Line line4 = Line.CreateBound( startPt4, endPt4 );

              // get the wall types we want
              WallType curtainWallType = null;
              WallType outerWallType = null;

              FilteredElementCollector wallTypeFec = new FilteredElementCollector( doc );
              ElementClassFilter wallTypesAreWanted = new ElementClassFilter( typeof( WallType ) );
              wallTypeFec.WherePasses( wallTypesAreWanted );
              List<Element> wallTypes = wallTypeFec.ToElements() as List<Element>;
              foreach( Element element in wallTypes )
              {
            WallType wallType = element as WallType;
            if( wallType != null )
            {
              if( wallType.Name == "Curtain Wall 1" )
              {
            curtainWallType = wallType;
              }
              if( wallType.Name == "Generic - 6\" Masonry" )
              {
            outerWallType = wallType;
              }
            }
              }

              // draw 4 walls
              Autodesk.Revit.DB.Document activeDoc = m_revitApp.ActiveUIDocument.Document;
              Wall wall1 = Wall.Create( activeDoc, line1, outerWallType.Id, level1.Id, 7.0, 0.0, false, false );
              Wall wall2 = Wall.Create( activeDoc, line2, curtainWallType.Id, level1.Id, 7.0, 0.0, false, false );
              Wall wall3 = Wall.Create( activeDoc, line3, curtainWallType.Id, level1.Id, 7.0, 0.0, false, false );
              Wall wall4 = Wall.Create( activeDoc, line4, curtainWallType.Id, level1.Id, 7.0, 0.0, false, false );

              FamilyInstance StructColumn1 = m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( startPt1, columnSymbol, wall1, level1, StructuralType.Column );
              FamilyInstance StructColumn2 = m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( startPt2, columnSymbol, wall2, level1, StructuralType.Column );
              FamilyInstance StructColumn3 = m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( startPt3, columnSymbol, wall3, level1, StructuralType.Column );
              FamilyInstance StructColumn4 = m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( startPt4, columnSymbol, wall4, level1, StructuralType.Column );

              int row = 5;
              int col = 8;

              double x = 5.0;
              double y = 11.0;
              double z = 0.0;

              XYZ refDirection = new XYZ( 1, 10, 0 );

              // place all the chairs
              for( int i = 0; i < row; i++ )
              {
            y = y + 8;
            for( int j = 0; j < col; j++ )
            {
              x = x + 5;
              XYZ location = new XYZ( x, y, z );
              FamilyInstance famInst = m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( location, chairSymbol, StructuralType.UnknownFraming );

              // flip the chairs 180 degrees
              XYZ pt = location;
              XYZ dir = GeomUtils.kZAxis;
              Line zAxis = Line.CreateUnbound( pt, dir );
              famInst.Location.Rotate( zAxis, GeomUtils.kRad180 );
            }
            x = x - ( col * 5 );
              }

              // place the desk
              XYZ deskPosition = new XYZ( 15.0, 8.0, 0.0 );
              m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( deskPosition, deskSymbol, StructuralType.UnknownFraming );

              // place the chair
              XYZ chairPosition = new XYZ( 18, 7.0, 0.0 );
              m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( chairPosition, chairMainSymbol, StructuralType.UnknownFraming );

              // place the door
              XYZ doorPosition = new XYZ( 46.0, 0.0, 0.0 );
              m_revitApp.ActiveUIDocument.Document.Create.NewFamilyInstance( doorPosition, doorSymbol, wall1, StructuralType.Brace );
        }