Revit
二次开发笔记
1.
选中图元
1.1
事先选择某类图元
(
Wall
)
Autodesk.Revit.UI.UIApplication
revit=commandData.Application;
ElementSet
collection=new
ElementSet();
ElementSet
selWall=new
ElementSet();
foreach(ElementIdelementIdinrevit.ActiveUIDocument.Selection.GetElementIds())
{
collection.Insert(revit.ActiveUIDocument.Document.GetElement(elementId));
//
选中的原件
}
foreach(Elementeleinsel)
{
Wallwall=eleasWall;
//
如果为墙
if(wall!=null)
{
SelWal.Insert(ele);
}
}
1.2.
通过交互方式
1.2.1
用矩形框选择图元
所用方法:
PickElementsByRectangle()
usingSystem.Collections.Generic;
//
声明引用命名空间,
Ilist
UIDocumentuidoc=commandData.Application.ActiveUIDocument;
ElementSetcollector=newElementSet();
IListelemList=uidoc.Selection.PickElementsByRectangle();
//
矩形框的应用
stringinfo="
所选图元:
";
foreach(ElementeleminelemList)
{
collector.Insert(elem);
info+="\n\t"+elem.ToString();
}
TaskDialog.Show("ChooseItems",info);
returnResult.Succeeded;