Automating the Building Maker workflow

Tobias suggested that it would be great to see the API used to create Walls by Face, Floors by Face, Roofs by Face, and Mass Floors.

Fortunately, the Revit API has FaceWall.Create and MassInstanceUtils.AddMassLevelDataToMassInstance methods.
Unfortunately, the Revit API has no methods to create Floors by Face and Roofs by Face.

Below is a code sample showing how to create Face Walls on the non-horizontal surfaces and Mass Floors for all levels.

public void CreateFaceWallsAndMassFloors()
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    FamilyInstance fi = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as FamilyInstance;  

    WallType wType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).Cast<WallType>().FirstOrDefault(q => q.Name == "Generic - 6\" Masonry");

    Options opt = new Options();
    opt.ComputeReferences = true;

    using (Transaction t = new Transaction(doc, "Create Face Walls & Mass Floors"))
        foreach(Solid solid in fi.get_Geometry(opt).Where(q => q is Solid).Cast<Solid>() )
            foreach(Face f in solid.Faces)
                  if (!FaceWall.IsValidFaceReferenceForFaceWall(doc, f.Reference))
                FaceWall.Create( doc, wType.Id, WallLocationLine.CoreExterior, f.Reference );


        foreach (Level level in new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>())
            MassInstanceUtils.AddMassLevelDataToMassInstance(doc, fi.Id, level.Id);


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s