BuildingCoder.CmdFaceWall.CreateFaceWalls C# (CSharp) Метод

CreateFaceWalls() статический приватный Метод

static private CreateFaceWalls ( Document doc ) : void
doc Document
Результат void
        static void CreateFaceWalls(
            Document doc)
        {
            Application app = doc.Application;

              Document massDoc = app.NewFamilyDocument(
            _conceptual_mass_template_path );

              CreateMassExtrusion( massDoc );

              //if( File.Exists( _family_path ) )
              //  File.Delete( _family_path );

              SaveAsOptions opt = new SaveAsOptions();
              opt.OverwriteExistingFile = true;

              massDoc.SaveAs( _family_path, opt );

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "Create FaceWall" );

            if( !doc.LoadFamily( _family_path ) )
              throw new Exception( "DID NOT LOAD FAMILY" );

            Family family = new FilteredElementCollector( doc )
              .OfClass( typeof( Family ) )
              .Where<Element>( x => x.Name.Equals( _family_name ) )
              .Cast<Family>()
              .FirstOrDefault();

            FamilySymbol fs = doc.GetElement(
              family.GetFamilySymbolIds().First<ElementId>() )
            as FamilySymbol;

            // Create a family instance

            Level level = doc.ActiveView.GenLevel;

            FamilyInstance fi = doc.Create.NewFamilyInstance(
              XYZ.Zero, fs, level, StructuralType.NonStructural );

            doc.Regenerate(); // required to generate the geometry!

            // Determine wall type.

            WallType wallType = new FilteredElementCollector( doc )
              .OfClass( typeof( WallType ) )
              .Cast<WallType>()
              .Where<WallType>( x => FaceWall.IsWallTypeValidForFaceWall( doc, x.Id ) )
              .FirstOrDefault();

            // Retrieve mass element geometry.

            Options options = app.Create.NewGeometryOptions();
            options.ComputeReferences = true;

            //options.View = doc.ActiveView; // conceptual mass is not visible in default view

            GeometryElement geo = fi.get_Geometry( options );

            // Create a sloped wall from the geometry.

            foreach( GeometryObject obj in geo )
            {
              Solid solid = obj as Solid;

              if( null != solid )
              {
            foreach( Face f in solid.Faces )
            {
              Debug.Assert( null != f.Reference,
                "we asked for references, didn't we?" );

              PlanarFace pf = f as PlanarFace;

              if( null != pf )
              {
                XYZ v = pf.FaceNormal;

                // Errors:
                //
                // Could not create a face wall.
                //
                // Caused by using ActiveView.Level
                // instead of ActiveView.GenLevel.
                //
                // This reference cannot be applied to a face wall.
                //
                // Caused by using this on a horizontal face.

                if( !Util.IsVertical( v ) )
                {
                  FaceWall.Create(
                    doc, wallType.Id,
                    WallLocationLine.CoreCenterline,
                    f.Reference );
                }
              }
            }
              }
            }
            tx.Commit();
              }
        }