您的位置:首页 > 其它

Revit 2011二次开发之得到选择的对象

2011-03-19 22:05 465 查看
start

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Document_Selection : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
try
{
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);
}

//得到当前文档中门的ID
ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
LogicalAndFilter doorsInstancefilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);
FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
ICollection<ElementId> doors = collector.WherePasses(doorsInstancefilter).ToElementIds();
string prompt = "the ids of the doors in the current document are:";
foreach (ElementId id in doors)
{
prompt += "\n\t" + id.IntegerValue;
}
TaskDialog.Show("Revit", prompt);
}
catch (Exception e)
{
messages = e.Message;
return Result.Failed;
}
return Result.Succeeded;
}
}end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: