Revit2016
二次开发笔记
1.
选中图元
1.1
事先选择某类图元
(
Wall
)
Autodesk.Revit.UI.UIApplication
revit = commandData.Application;
ElementSet
collection = new
ElementSet();
ElementSet
selWall = new
ElementSet();
foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds())
{
collection.Insert(revit.ActiveUIDocument.Document.GetElement(elementId));
//
选中的原件
}
foreach (Element ele in sel)
{
Wall wall = ele as Wall;
//
如果为墙
if (wall !=null)
{
SelWal.Insert(ele);
}
}
1.2.
通过交互方式
1.2.1
用矩形框选择图元
所用方法:
PickElementsByRectangle()
using System.Collections.Generic;
//
声明引用命名空间,
Ilist
UIDocument uidoc = commandData.Application.ActiveUIDocument;
ElementSet collector = new ElementSet();
IList elemList = uidoc.Selection.PickElementsByRectangle();
//
矩形框的应用
string info = "
所选图元:
";
foreach (Element elem in elemList)
{
collector.Insert(elem);
info += "\n\t" + elem.ToString();
}
TaskDialog.Show("Choose Items", info);
return Result.Succeeded;