我们使用ElementClassFilter来过滤Element的时候,经常会碰到一些异常,例如下面的:
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.
很庆幸,异常里面已经给出了指导意见,于是,以DetailLine作为例子,我们可以这样来过滤出我们想要的DetailLine:
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
}
}
}
经过一番研究,我把所有ElementClassFilter不支持的类以及替代的类列在了下表中:
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 |
注意: Element是一个特例, 它也不能在ElementClassFilter中使用,其中一个我常用的替代方案是这样的,用到了逻辑或LogicalOrFilter:
new LogicalOrFilter (new ElementIsElementTypeFilter( false),
new ElementIsElementTypeFilter (true ));