Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET Creations API: Create Levels

$
0
0

In Revit .NET API 2013, though the NewWall method has been moved to the Wall class itself, the Level generation method has not. It is still in the Document.Create instance. Anyway, we figured where it is and were able to create Levels.

In this article, let’s work out a simple and functional help method and use it to create some levels. Here is the code.

    public class LevelCreation
    {
        public static List<Level> CreateLevels(RvtDocument doc, double[] elevations, string[] names = null)
        {
            List<Level> list = new List<Level>();

            for (int i = 0; i < elevations.Length; i++)
            {
                double elevation = elevations[i];
                Level level = doc.Create.NewLevel(elevation);
                if (names != null && names.Length >= i + 1)
                    level.Name = names[i];

                list.Add(level);
            }

            return list;
        }

}


CachedDoc.Delete(new FilteredElementCollector(CachedDoc)
                    .WherePasses(new ElementClassFilter(typeof(Level), false))
                    .Select(e => e.Id)
                    .ToList());                   
List<Level> levels = LevelCreation.CreateLevels(
        CachedDoc,
        new double[]
        {
            0.0,
            9.0,
            9.0 + 8.0,
            9.0 + 8.0 + 7.0,
            9.0 + 8.0 + 7.0 + 6.0,
            9.0 + 8.0 + 7.0 + 6.0 + 5.0,
            9.0 + 8.0 + 7.0 + 6.0 + 5.0 + 4.0,
            9.0 + 8.0 + 7.0 + 6.0 + 5.0 + 4.0 + 3.0,
            9.0 + 8.0 + 7.0 + 6.0 + 5.0 + 4.0 + 3.0 + 2.0
        },
        new string[]
        {
            "L0",
            "L1",
            "L2",
            "L3",
            "L4",
            "L5",
            "L6",
            "L7",
            "L8",
        }
    );
...

Here is what the Levels look like in Revit.
 Levels

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles