#RTCNA Wish 1 granted! Export wall type layer information

Jason wished that the API could be used to “create a data dump of wall types to show the different layers and assigned materials

Two things to consider: Curtain and stacked walls don’t have layers, and <By Category> has no material element ID

public void exportWallTypeStructure()
{
    Document doc = this.ActiveUIDocument.Document;
    
    // set name of output file
    string output = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(doc.PathName) + "-walls.txt");
    
    // create file for writing, overwriting an existing file with the same name if it exists
    using (StreamWriter sw = new StreamWriter(output, false))
    {
        // look at all basic wall types (not stacked & curtain walls)
        foreach (WallType wt in new FilteredElementCollector(doc).OfClass(typeof(WallType)).Cast<WallType>().Where(q => q.Kind == WallKind.Basic))
        {
            sw.Write(wt.Name + ","); // write the name of the wall type
            
            // iterate through every layer in the wall
            foreach (CompoundStructureLayer layer in wt.GetCompoundStructure().GetLayers())
            {
                Element material = doc.GetElement(layer.MaterialId);
                
                // handle case when ID is -1 because layer does not have a material assigned
                string mname = "<By Category>";
                if (material != null)
                    mname = material.Name;
                
                sw.Write(mname + " = " + layer.Width + ",");
            }
            sw.Write(Environment.NewLine);
        }
    }
    Process.Start(output); //open the output file
}

Sample Output:
Generic - 6",<By Category> = 0.5,
Interior - 5" Partition (2-hr),Gypsum Wall Board = 0.0520833333333333,Gypsum Wall Board = 0.0520833333333333,Metal Stud Layer = 0.208333333333333,Gypsum Wall Board = 0.0520833333333333,Gypsum Wall Board = 0.0520833333333333,
Exterior - Brick on Mtl. Stud,Brick, Common = 0.302083333333333,Air = 0.25,Air Infiltration Barrier = 0,Plywood, Sheathing = 0.0625,Metal Stud Layer = 0.5,Vapor Retarder = 0,Gypsum Wall Board = 0.0416666666666667,
Generic - 8",<By Category> = 0.666666666666667,
Exterior - Brick on CMU,Brick, Common = 0.302083333333333,Air = 0.25,Rigid insulation = 0.25,Damp-proofing = 0,Concrete Masonry Units = 0.635416666666667,Metal Furring = 0.135416666666667,Gypsum Wall Board = 0.0520833333333333,
Generic - 12",<By Category> = 1,
Generic - 5",<By Category> = 0.416666666666667,
Generic - 12" Masonry,Concrete Masonry Units = 0.96875,
Generic - 8" Masonry,Concrete Masonry Units = 0.635416666666667,
Generic - 6" Masonry,Concrete Masonry Units = 0.46875,

Advertisements

3 thoughts on “#RTCNA Wish 1 granted! Export wall type layer information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s