https://blog.csdn.net/birdfly2015/article/details/87883233
1.创建一个wpf项目,引用RevitAPI和RevitUI
2.入口
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
class WpfAddin : IExternalCommand
{
public static ExternalEvent externalEvent;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
CeilingCreateEventHandler createEventHandler = new CeilingCreateEventHandler();
externalEvent = ExternalEvent.Create(createEventHandler);
MainWindow.CeilingCreateEE = externalEvent;
MainWindow wpf = new MainWindow();//实例化主窗口类
wpf.Show();//展示界面
return Result.Succeeded;
}
}
3.事件
[Transaction(TransactionMode.Manual), Regeneration(RegenerationOption.Manual)]
public class CeilingCreateEventHandler : IExternalEventHandler
{
public void Execute(UIApplication app)
{
TaskDialog.Show("sss","sss");
}
public string GetName()
{
return "";
}
}
4.触发事件
public static ExternalEvent CeilingCreateEE;
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CeilingCreateEE.Raise();
}