Showing posts with label walls. Show all posts
Showing posts with label walls. Show all posts

Thursday, January 13, 2011

Retrieving Classes and Categories from the 'Main Model'

We just got another 5 or 6 inches of snow over the last couple of days.  After the foot or so that we had over Christmas (that quickly melted once it got up to the 60's for a day!) I believe this is probably the most snow we've had this early for quite some time.

I'm working on a material collection project in Revit right now.  Part of this collection hinges on  obtaining a plus-minus report that lists all elements and their properties for each 'option set' in the house.

Revit has a 'DesignOption' field for each element, whether it be a system family or a custom family, that defaults to 'Main Model.'  Once the item is placed into a design option, this is obviously changed to the design option id in the database. Here I get an IList<T> of the walls in the main model:

/*Walls in Main Model*/
BuiltInParameter bip = BuiltInParameter.DESIGN_OPTION_PARAM;
ParameterValueProvider provider = new ParameterValueProvider(new ElementId(bip));
FilterStringRuleEvaluator evaluator = new FilterStringEquals();
FilterRule rule = new FilterStringRule(provider, evaluator, "Main Model", false);
ElementParameterFilter filter = new ElementParameterFilter(rule);


FilteredElementCollector collectorCoreWalls = new 
    FilteredElementCollector(m_doc).OfClass(typeof(Wall)).WherePasses(filter);
IList<Element> coreWalls = collectorCoreWalls.ToElements();

The same can be done for Floors (Floor), Roofs (RoofBase), Ceilings and Floors (CeilingAndFloor) and others.

Next post I'll show how to loop through Design Option Elements.

Tuesday, January 11, 2011

Retrieving a wall's Function Parameter (BuiltInParameter.FUNCTION_PARAM)

For part of a large Revit material-gathering project I'm working on, I need to retrieve a wall's function. Walls can be assigned six functions from within their type properties:

  • Interior
  • Exterior
  • Foundation
  • Retaining
  • Soffit
  • Core-Shaft

At first I thought it would be fairly straight-forward, and I'd just do this grab the valuestring of the 'FUNCTION_PARAM' like so:

eWall.get_Parameter("Function").AsValueString()

But that gave me a NULL value and crashed Revit. The approach that worked for me was this:

static public string IsExterior(Element e, Document doc)
{
    ElementId id = e.GetTypeId();
    ElementType wallType = doc.get_Element(id) as ElementType;

    Parameter wallFunction = wallType.get_Parameter
        (BuiltInParameter.FUNCTION_PARAM);
    WallFunction value  = (WallFunction)wallFunction.AsInteger();

    return value.ToString();
}
Thanks to Jeremy Tammik's SDK example for setting me straight.