|
观看叶老师的过滤对象视频,照着老师的代码写了下来,然后发现同样的代码我的Revit确运行不了,并且出现了图片中的错误。代码和图片如下
图片中提示的应该就是我加粗变色的那行代码的错误,但是我都指定的是第一个元素,然而还提示我图中的错误,或者是我选择的对象出现了问题?
namespace FindRoomInLevle
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class FindRoomInLevle1:IExternalCommand
{
public Result Execute(ExternalCommandData commandData,ref string messages,ElementSet elements)
{
UIApplication app= commandData.Application;
Document document = app.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(document);//创建一个单元过滤器
ICollection<Element> Levels = collector.OfClass(typeof(Level)).ToElements();
var query = from element in collector
where element.Name == “Level1”
select element;
//获得楼层编号
List<Element> level1 =query.ToList<Element>();
ElementId levelId = level1[0].Id;
//找到一层的所有的墙
ElementLevelFilter level1Filter = new ElementLevelFilter(levelId); //创建一个楼层过滤器
collector = new FilteredElementCollector(document);
ICollection<Element> allWallsOnLevel1 = collector.OfClass(typeof(Wall)).WherePasses(level1Filter).ToElements();
TaskDialog.Show("在一层的墙的数目", allWallsOnLevel1.Count.ToString());
return Result.Succeeded;
}
}
}
|
|