RevitAPI: 不支持ElementClassFilter的那些类

我们使用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.AreaReinforcementCurveCurveElement
CurveByPointsCurveElement
DetailCurveCurveElement
DetailArcCurveElement
DetailEllipseCurveElement
DetailLineCurveElement
DetailNurbSplineCurveElement
ModelCurveCurveElement
ModelArcCurveElement
ModelEllipseCurveElement
ModelHermiteSplineCurveElement
ModelLineCurveElement
ModelNurbSplineCurveElement
SymbolicCurveCurveElement
Architecture.RoomSpatialElement
AreaSpatialElement
Mechanical.SpaceSpatialElement
Architecture.RoomTagSpatialElementTag
AreaTagSpatialElementTag
Mechanical.SpaceTagSpatialElementTag
AnnotationSymbolTypeFamilySymbol
AreaTagTypeFamilySymbol
Architecture.RoomTagTypeFamilySymbol
Mechanical.SpaceTagTypeFamilySymbol
Structure.TrussTypeFamilySymbol
AnnotationSymbolFamilyInstance
MullionFamilyInstance
PanelFamilyInstance
Architecture.FasciaHostedSweep
Architecture.GutterHostedSweep
SlabEdgeHostedSweep
CombinableElementa combination of GenericForm and GeomCombination

注意: Element是一个特例, 它也不能在ElementClassFilter中使用,其中一个我常用的替代方案是这样的,用到了逻辑或LogicalOrFilter:

new LogicalOrFilter (new ElementIsElementTypeFilter( false), 
    new ElementIsElementTypeFilter (true ));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值