您的位置:首页 > 其它

Revit 二次开发之“交互操作-得到选择的对象”

2011-03-18 08:46 399 查看
进入选择对象状态使用Selection.PickObject();函数。
异常处理有固定格式。

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class GetSelect : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
try
{
if (null == commandData)
{
throw new ArgumentNullException("commandData");
}

UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;

Reference refelem = null;//类似C#中的Object基类
IList<Duct> ducts = new List<Duct>();
IList<XYZ> xyzs = new List<XYZ>();

for (int i = 1; i < 5; i++)
{
//没有提示文字
refelem = sel.PickObject(ObjectType.Element, "请选择第 " + i.ToString() + " 个对象");
if (refelem.Element is Duct)
{
ducts.Add(refelem.Element as Duct);
xyzs.Add(refelem.GlobalPoint);
MessageBox.Show("选择了一个风管");
}
else
{
MessageBox.Show("请选择风管");
}
}
MessageBox.Show("你选择了" + ducts.Count + "个风管");

}
catch (Exception e)
{
messages = e.Message;
return Result.Failed;
}

return Result.Succeeded;
}
}end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: