描述
- 选择元素、模型
- 选择时单选、框选
- 选择时根据类型选择
- 取消时不报错,已封装处理
用途
- 用于手动选择元素,适应各种情况选择
效果
示例(更多封装Utils,微信公众号回复“选择元素”自取)
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using TuoLuoUtils;
namespace RevitDemo
{
/// <summary>
/// 选择元素
/// </summary>
[Transaction(TransactionMode.Manual)]
public class SelectElement : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
//单选,Element
Element elem = uiDoc.PickElementByElementType<Element>();
TaskDialog.Show("选择", "已选择:" + elem.Name);
//单选,只选Floor
Floor floor = uiDoc.PickElementByElementType<Floor>();
TaskDialog.Show("选择", "已选择:" + floor.FloorType.FamilyName);
//多选,只选Wall
List<Wall> walls = uiDoc.PickElementsByElementType<Wall>();
string wallNameId = string.Empty;
foreach (var wall in walls)
{
wallNameId += "\n" + wall.WallType.FamilyName + " Id " + wall.Id;
}
TaskDialog.Show("选择", "已选择:" + wallNameId);
return Result.Succeeded;
}
}
}
关于笔者
我是旋转De陀螺,笔者将持续分享Revit二次开发思路及入门经验,感谢点赞、关注、留言、一键三连,获取更多分享。
- 微信公众号: BIM开发
- QQ群: 1009105743
- CSDN: 旋转De陀螺
- 知乎: 旋转De陀螺