WPF的学习和使用二:WPF 与 Revit 的进阶交互 @Revit二次开发
在WPF与Revit的普通交互过程中,我们一次只能调用一个外部命令,也就是说在交互界面上,只能有一个按钮给我们操作。对于多按钮,多命令的执行需要下,我们就需要使用外部事件了。
外部事件的使用
外部事件使用的接口是IExternalEventHandler,一般用于你直接调取的命令上,Handler本意是操作员、搬运工的意思,还是以创建墙为例,代码如下:
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExternalEventDemo
{
class CreateWall : IExternalEventHandler
{
public double WallHeight{
get; set; }
public void Execute(UIApplication app)
{
// 【1】获取当前文档
// Document doc = commandData.Application.ActiveUIDocument.Document;
Document doc = app.ActiveUIDocument.Document;
MainWindow mainWindow = new MainWindow();
double height = WallHeight / 0.3048;
// 【2】获取族实例为 CL_W1 的墙:
FilteredElementCollector collector = new FilteredElementCollector(doc);
Element ele = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType