Revit 2011二次开发之得到选择的对象
start
end
[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;
}
}
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。