Revit二次开发之“让对象处于被选择状态”
要想让对象被选择,需要知道对象的ID比如506025
from:http://revit.5d6d.com/thread-864-1-4.html
uidoc.Selection.Elements.Add(element);
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class OpenDoc : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
//得到选择的对象
//Selection selection = uidoc.Selection;
//ElementSet collection = selection.Elements;
//if (0 == collection.Size)
//{
// TaskDialog.Show("Revit", "You haven't selected any elements");
//}
//else
//{
// string info = "Ids of selected elements in the document are:";
// foreach (Element elem in collection)
// {
// info += "\n\t" + elem.Id.IntegerValue;
// }
// TaskDialog.Show("Revit", info);
//}
Element el = uidoc.Document.get_Element(new ElementId(506025));//得到对象
SelElementSet selElements = uidoc.Selection.Elements;//添加到选择集里
selElements.Add(el);
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class OpenDoc : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
//得到选择的对象
//Selection selection = uidoc.Selection;
//ElementSet collection = selection.Elements;
//if (0 == collection.Size)
//{
// TaskDialog.Show("Revit", "You haven't selected any elements");
//}
//else
//{
// string info = "Ids of selected elements in the document are:";
// foreach (Element elem in collection)
// {
// info += "\n\t" + elem.Id.IntegerValue;
// }
// TaskDialog.Show("Revit", info);
//}
Element el = uidoc.Document.get_Element(new ElementId(506025));//得到对象
SelElementSet selElements = uidoc.Selection.Elements;//添加到选择集里
selElements.Add(el);
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。