首页 > 代码库 > Revit 二次开发 自动选中对象

Revit 二次开发 自动选中对象


//
获取选中对象 [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class setSelectEle : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { SetSelectionElement(commandData, elements); return Result.Succeeded; } public void SetSelectionElement(ExternalCommandData commandData, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; //获取id为729401的Element ElementId el = new ElementId(729401);
     Element e = doc.GetElement(el);
        Selection sel = app.ActiveUIDocument.Selection;  
     Transaction trans
= new Transaction(doc);
     trans.Start(
"SetSelection");

     //添加到当前选择集中
     sel.Elements.Add(e);

     trans.Commit();
  }

}