By Aaron Lu
When we are using ElementClassFilter to filter elements, we may get this kind of Exception:
Autodesk.Revit.Exceptions.ArgumentException: Input type(Autodesk.Revit.DB.DetailLine) is of an element type that exists in the API, but not in Revit's native object model. Try using Autodesk.Revit.DB.CurveElement instead, and then postprocessing the results to find the elements of interest.
As the exception message suggested, we can use its base class to filter them, and then post process the result, let's see an example code:
var lineFilter = new ElementClassFilter( typeof( CurveElement)); FilteredElementCollector filteredElements = new FilteredElementCollector (familyDoc ); filteredElements = filteredElements.WherePasses( lineFilter); foreach (CurveElement element in filteredElements ) { DetailLine detailLine = element as DetailLine; if ( detailLine != null) { var curv = detailLine .Location as LocationCurve; var lin = curv. Curve as Line; if ( lin != null) { // do what you like } } }
After a short investigation, I found all of those Element derived types and their substitutions as for Revit 2015, see below list:
Structure.AreaReinforcementCurve | CurveElement |
CurveByPoints | CurveElement |
DetailCurve | CurveElement |
DetailArc | CurveElement |
DetailEllipse | CurveElement |
DetailLine | CurveElement |
DetailNurbSpline | CurveElement |
ModelCurve | CurveElement |
ModelArc | CurveElement |
ModelEllipse | CurveElement |
ModelHermiteSpline | CurveElement |
ModelLine | CurveElement |
ModelNurbSpline | CurveElement |
SymbolicCurve | CurveElement |
Architecture.Room | SpatialElement |
Area | SpatialElement |
Mechanical.Space | SpatialElement |
Architecture.RoomTag | SpatialElementTag |
AreaTag | SpatialElementTag |
Mechanical.SpaceTag | SpatialElementTag |
AnnotationSymbolType | FamilySymbol |
AreaTagType | FamilySymbol |
Architecture.RoomTagType | FamilySymbol |
Mechanical.SpaceTagType | FamilySymbol |
Structure.TrussType | FamilySymbol |
AnnotationSymbol | FamilyInstance |
Mullion | FamilyInstance |
Panel | FamilyInstance |
Architecture.Fascia | HostedSweep |
Architecture.Gutter | HostedSweep |
SlabEdge | HostedSweep |
CombinableElement | a combination of GenericForm and GeomCombination |
Note: A special case is Element, which can not be used either, one alternative I like is using LogicalOrFilter, example:
new LogicalOrFilter (new ElementIsElementTypeFilter( false), new ElementIsElementTypeFilter (true ));