1

Has anyone got any code to get the length of a wall? Currently I use:

ElementCategoryFilter wallsFilter = 
  new ElementCategoryFilter(BuiltInCategory.OST_Walls);

FilteredElementCollector collector = new FilteredElementCollector(Doc);
IList<Element> walls =
  collector.WherePasses(wallsFilter).WhereElementIsNotElementType().ToElements();

foreach (Element wall in walls)
  MessageBox.Show(wall.get_Parameter("Length").AsString());

Length comes back empty!!!

skeletank
  • 2,880
  • 5
  • 43
  • 75
Richard Banks
  • 2,946
  • 5
  • 34
  • 71

1 Answers1

1

AsString() assumes that the parameter is of string type (Parameter.StorageType == StorageType.String). This length parameter is a double length measurement. So AsDouble() should work. Or you can use AsValueString() to convert the value to a string with units as would be seen in the UI.

You could also switch to use BuiltInParameter.CURVE_ELEM_LENGTH instead of "Length" as a string. This would be useful if the application is to be localized.

Zoinks
  • 810
  • 7
  • 4