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
[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
相关文章推荐
- Revit 二次开发之“交互操作-得到选择的对象”
- Revit 2011二次开发“弹出对话框,得到输入的值”
- Revit二次开发高级专题讲座:访问Revit模型中的几何数据以及对象间关系判断方法(点击下载)
- [Unity3D]Unity3D游戏开发3D选择场景中的对象,并显示轮廓效果强化版
- Creo二次开发--函数(6)--选择对象
- Revit二次开发之“得到对象的所属类型”
- Android开发——相册拍照_02.将拍照得到或相册中选择的图片显示在ImageView中
- Revit开发之选择链接模型中的构件
- HTML5开发之通过文件对象选择文件
- 转换流的使用,和装饰类的应用,以及开发时该怎样选择要使用的对象
- Revit二次开发之“添加对象到选择集”
- Building Coder(Revit 二次开发) - NewFamilyInstance() 重载版本的选择
- Revit 二次开发 自动选中对象
- Revit 二次开发 获取选中的对象
- [MOSS开发]:对象集合的迭代选择foreach还是forloop
- Revit二次开发之“让对象处于被选择状态”
- 近期.NET学习及项目开发整理-弹出对话框显示 是否 然后得到 选择的结果
- Building Coder(Revit 二次开发) - 对象关系
- Revit 二次开发 修改对象的颜色
- Revit API 开发 (5): 如何得到所有的categories,创建共享参数,并把它们绑定在一起