Here’s the last wish granted! RVT Links are used to model typical floors and parts are created from the walls and floors in the link instances. Here is how to use the API to set a user-created “Level” parameter for each part based on the name of the level in the host RVT nearest to the lowest point in the geometry of each part.
public void setPartLevel()
{
Document doc = this.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc, "Set Part Levels"))
{
t.Start();
foreach (Part part in new FilteredElementCollector(doc).OfClass(typeof(Part)))
{
Parameter levelParam = part.Parameters.Cast<Parameter>().FirstOrDefault(q => q.Definition.Name == "Level");
if (levelParam == null)
return;
double minZ = double.PositiveInfinity;
foreach (Solid s in part.get_Geometry(new Options()))
{
foreach (Face f in s.Faces)
{
foreach (EdgeArray ea in f.EdgeLoops)
{
foreach (Edge e in ea)
{
Curve c = e.AsCurve();
if (c.GetEndPoint(0).Z < minZ)
minZ = c.GetEndPoint(0).Z;
if (c.GetEndPoint(1).Z < minZ)
minZ = c.GetEndPoint(1).Z;
}
}
}
}
Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().OrderBy(q => Math.Abs(q.Elevation - minZ)).FirstOrDefault();
levelParam.Set(level.Name);
}
t.Commit();
}
}
Advertisements