Revit 二次开发之“交互操作-得到选择的对象”
进入选择对象状态使用Selection.PickObject();函数。
异常处理有固定格式。
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;
}
}
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。