Filter by Element Class
Using OfClass Shortcut
OfClassapplies a class filter (ElementFilterClass) toFilteredElementCollector.- Example:
ins = FilteredElementCollector(doc).OfClass(FamilyInstance)
Main Revit API Classes
AssemblyInstance,AssemblyType,BeamSystemTypeCADLinkType,Ceiling,CeilingAndFloorCurtainSystem,Dimension,DirectShapeFamily,FamilyInstance,FilledRegionFloor,FloorType,GridImageType,ImageView,IndependentTagLevel,LevelType,MEPCurveMaterial,ModelText,ModelTextTypePanelType,ParameterElement,PhaseProjectInfo,ProjectLocation,PropertyLineRevision,RevitLinkInstance,RoofTypeSharedParameterElement,SlabEdge,SlabEdgeTypeSweep,SweepType,TableViewTextElement,TextElementType,TilePatternView3D,ViewFamilyType,ViewPlanViewPlanType,ViewSchedule,ViewSectionViewSheet,Viewport,WallFoundationWallFoundationType,WallSweep,WallType
Importing Necessary Libraries
- To search for specific elements like
PipeSegment, import the relevant library:from Autodesk.Revit.DB.Plumbing import *
Constructing Filter Instance
- Allows flexibility to invert the filter.
- Example without inversion:
Filter = ElementClassFilter(Material)
allMat = FilteredElementCollector(doc).WherePasses(Filter).ToElements() - Example with inversion:
InvertFilter = ElementClassFilter(Material, True)
allMat = FilteredElementCollector(doc).WherePasses(InvertFilter).ToElements()
Note: Using the OfClass shortcut is quicker and more elegant if inversion is not needed.
Copy code
InvertFilter = ElementClassFilter(Material, True)
allMat = FilteredElementCollector(doc).WherePasses(InvertFilter).ToElements()
Note: If you do not need to invert the filter, it will be quicker and more elegant to use the shortcut, as discussed at the beginning of this section.