This should be pretty simple in Revit 2020 API but I can’t seem to get it.
I’m trying Select a Detail Component Family in the Project to be able to place it in a view.
- Family Category = Detail Component
- Family Name = myFamilyName
- FamilySymbol Type = myFamilySymbolTypeName
I’m stuck on the filtering first part. I can get all the Family Names in the project, but I can’t seem to filter them out by BuiltInCategory to only shown loaded Detail Components?
FilteredElementCollector collector2 = new FilteredElementCollector(doc);
ICollection<Element> ele2 = collector2
.OfClass(typeof(Family))
.OfCategory(BuiltInCategory.OST_DetailComponents) //This is where its not working. If I comment this out, I get all Familes in Project
.ToElements();
StringBuilder sb2 = new StringBuilder();
foreach (Element el2 in ele2)
{
sb2.AppendLine(el2.Name);
}
TaskDialog.Show("reavit", sb2.ToString());
It’s Python instead of C, but this should help:
adds the common language runtime to the Iron Python environment
import clr
#adds the Revit Services DLL to the CLR
clr.AddReference("RevitServices")
#adds the Revit Services namespace to the Iron Python environment
import RevitServices
#adds the document manager to the Iron Python environment
from RevitServices.Persistence import DocumentManager
#adds the Revit API to the CLR
clr.AddReference("RevitAPI")
#adds the FilterElementCollector, BuiltInCategory, and FamilySymbol classes to the Iron Python environment
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, FamilySymbol
#sets the doc variable to the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument
#constructs a new filtered element collector, ensuring we're only getting detail components; of the class family symbol; and returning those as elements
builtInCollector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(FamilySymbol).WhereElementIsElementType().ToElements()
#note that if you omit the '.OfClass(FamilySymbol)' section you'll return the filled region types as well
#sends the results of the builtInCollector to the Dynamo environment
OUT = builtInCollector
1 Like
No this is where I’m stuck. It will get all detail items (filled regions etc which I don’t want) but using the
.OfClass(FamilySymbol)
Doesn’t work in this context.
Found it. was missing the typeof…in .OfClass(typeof(FamilySymbol)
Final is:
FilteredElementCollector collector2 = new FilteredElementCollector(doc);
ICollection<Element> ele2 = collector2
.OfCategory(BuiltInCategory.OST_DetailComponents)
.OfClass(typeof(FamilySymbol))
.WhereElementIsElementType()
.ToElements();
1 Like