There’s been a bunch of discussion in the Autodesk forum about how to get the total length of multiple elements.
Here’s an API solution that works with lines, walls, beams, conduit, or anything else with a “Length” parameter
public void lineLength()
{
double length = 0;
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
ICollection<ElementId> ids = uidoc.Selection.GetElementIds();
foreach (ElementId id in ids)
{
Element e = doc.GetElement(id);
Parameter lengthParam = e.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);
if (lengthParam == null)
continue;
length += lengthParam.AsDouble();
}
string lengthWithUnits = UnitFormatUtils.Format(doc.GetUnits(), UnitType.UT_Length, length, false, false);
TaskDialog.Show("Length", ids.Count + " elements = " + lengthWithUnits);
}
Thanks
Sent from my iPhone
>
[…] Total length of multiple lines […]
Hey I’ve been using this amazing API, but in Revit 2021
Autodesk.Revit.DB.UnitFormatUtils.Format and
Autodesk.Revit.DB.UnitType
became obsolete, rendering this Api ineffective
what is the new Code?
Please see https://boostyourbim.wordpress.com/2020/06/10/2021-changes-units/
Great….Thanks