Today was the last day of the Revit programming training here in Barcelona.
One of the items we examined is
yesterday’s suggestion
to use API filtering and the HOST_ID_PARAM to select the doors and windows hosted by a specific wall. Here is a code snippet that implements this and displays the result in a message box:
ElementId id = wall.Id;
Type t = typeof( FamilyInstance );
BuiltInCategory bicd = BuiltInCategory.OST_Doors;
BuiltInCategory bicw = BuiltInCategory.OST_Windows;
BuiltInParameter bip = BuiltInParameter.HOST_ID_PARAM;
Autodesk.Revit.Creation.Filter cf = app.Create.Filter;
Filter f1 = cf.NewCategoryFilter( bicd );
Filter f2 = cf.NewCategoryFilter( bicw );
Filter f3 = cf.NewLogicOrFilter( f1, f2 );
Filter f4 = cf.NewTypeFilter( t );
Filter f5 = cf.NewLogicAndFilter( f3, f4 );
Filter f6 = cf.NewParameterFilter( bip,
CriteriaFilterType.Equal, id );
Filter f7 = cf.NewLogicAndFilter( f5, f6 );
List<Element> hosted = new List<Element>();
doc.get_Elements( f7, hosted );
n = hosted.Count;
string s = string.Format(
"Wall <{0} {1}> hosts {2} door"
+ " and window element{3}{4}n",
wall.Name, id.Value, n,
( ( 1 == n ) ? "" : "s" ),
( ( 0 == n ) ? "." : ":" ) );
foreach( FamilyInstance fi in hosted )
{
s += string.Format( "n {0} {1} {2}",
fi.Category.Name, fi.Name, fi.Id.Value );
}
MessageBox.Show( s, "Anfitrion" );
In case you are wondering, ‘anfitrión’ means ‘host’ in Spanish.

Leave a Reply