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
异常处理有固定格式。
[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
相关文章推荐
- Revit 2011二次开发之得到选择的对象
- (c#)AutoCAD二次开发,运行时,出现“对象的当前状态使该操作无效”
- Creo二次开发--函数(6)--选择对象
- Revit 二次开发 获取选中的对象
- Building Coder(Revit 二次开发)- 在新建族中进行镜像操作,并切换当前视图
- Building Coder(Revit 二次开发) - 布尔操作和 InstanceVoidCutUtils
- Building Coder(Revit 二次开发) - 对象关系
- Revit 二次开发 自动选中对象
- VSTO Office二次开发PPTRibbonX命令操作及对象添加
- Revit 二次开发 修改对象的颜色
- VSTO Office二次开发PPTRibbonX命令操作及对象添加
- Building Coder(Revit 二次开发) - NewFamilyInstance() 重载版本的选择
- CAD 二次开发 图层操作(3)取得指定图层下的所有对象id
- Building Coder(Revit 二次开发) - 拖放API
- 由 uiautomator 二次开发得到的启发以及完善
- 面对对象之差异化的网络数据交互方式--单机游戏开发之无缝切换到C/S模式
- Revit 二次开发 获取明细表中的过滤条件信息
- uchome二次开发 数据库操作
- Revit 2011 二次开发之“高亮显示错误提示”
- Revit二次开发示例:HelloRevit