要用:duct.ReferenceLevel
//
选择某一楼层上的墙
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
// [Journaling(JournalingMode.NoCommandData)]
public class SelectFloorObj : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
// 把标高1上的墙加入选择集
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
collector.OfClass( typeof (Wall)).OfCategory(BuiltInCategory.OST_Walls);
IList < Element > lists = collector.ToElements();
foreach (Element el in lists)
{
if (el.Level.Name == " 标高 1 " )
selection.Elements.Add(el); // 添加到选择集
}
// 风管的Level属性为空,不能这样做。
// FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
// collector.OfClass(typeof(Duct)).OfCategory(BuiltInCategory.OST_DuctCurves);
// IList<Element> lists = collector.ToElements();
// foreach (Element el in lists)
// {
// Duct duct = el as Duct;
// MessageBox.Show(duct.LevelOffset.ToString());
// if (duct.Level != null)
// {
// if (duct.Level.Name == "标高 1")
// {
// selection.Elements.Add(duct);
// }
// }
// }
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
// [Journaling(JournalingMode.NoCommandData)]
public class SelectFloorObj : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
// 把标高1上的墙加入选择集
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
collector.OfClass( typeof (Wall)).OfCategory(BuiltInCategory.OST_Walls);
IList < Element > lists = collector.ToElements();
foreach (Element el in lists)
{
if (el.Level.Name == " 标高 1 " )
selection.Elements.Add(el); // 添加到选择集
}
// 风管的Level属性为空,不能这样做。
// FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
// collector.OfClass(typeof(Duct)).OfCategory(BuiltInCategory.OST_DuctCurves);
// IList<Element> lists = collector.ToElements();
// foreach (Element el in lists)
// {
// Duct duct = el as Duct;
// MessageBox.Show(duct.LevelOffset.ToString());
// if (duct.Level != null)
// {
// if (duct.Level.Name == "标高 1")
// {
// selection.Elements.Add(duct);
// }
// }
// }
return Result.Succeeded;
}
}