#RTCNA wish granted (sort of) – slab edges on all floor edges

An API wish from Michael

Creating slab edges programmatically for all edges of a slab. The UI does not allow you to pick all edges of a slab in some cases. For example, on a slab edge that is sloping and curving in plan. Is there a way to get around this in the API by hard setting the reference curve?

It turns out that the limitation on sloping/curving edges still exists when we use the API, but in any case, below is the API code to create slab edges on all edges of the floor’s top face.

public void slabEdge()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    Floor floor = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Floor;
    Options options = new Options();
    options.ComputeReferences = true;
    Solid solid = null;
    foreach (Autodesk.Revit.DB.GeometryObject geomObj in floor.get_Geometry(options))
    {
        Autodesk.Revit.DB.Solid s = geomObj as Autodesk.Revit.DB.Solid;
        if (null != s)
        {
            if (s.Faces.Size > 0)
            {
                solid = s;
                break;
            }
        }
     }
        Face topFace = null;
        double bigZ = 0;
        foreach (Face f in solid.Faces)
        {
            PlanarFace pf = f as PlanarFace;
            if (pf == null)
                continue;
            if (pf.FaceNormal.Z > bigZ)
            {
                bigZ = pf.FaceNormal.Z;
                topFace = f;
            }
        }
        
        SlabEdgeType slabType = new FilteredElementCollector(doc).OfClass(typeof(SlabEdgeType)).Cast<SlabEdgeType>().FirstOrDefault();
        int ctr = 0;
        using (Transaction t = new Transaction(doc, "slab edges"))
        {
            t.Start();
            foreach (EdgeArray ea in topFace.EdgeLoops)
            {
                foreach (Edge e in ea)
                {
                    try
                    {
                     SlabEdge se = doc.Create.NewSlabEdge(slabType, e.Reference);
                     se.HorizontalFlip();
                     ctr++;
                    }
                    catch
                    {    
                    }
                }
            }
            t.Commit();
        }
        TaskDialog.Show("Info", ctr + " slab edges created");
}

One thought on “#RTCNA wish granted (sort of) – slab edges on all floor edges

Leave a comment