是否可以通过我创建的 Revit API 按钮打开我的 winForm?

Is it possible to open my winForm through Revit API button I have created?

我想 运行 我的 winForm 通过我在 Revit 中创建的按钮 API,但我是这个领域的新手,我现在有点卡住了。

在我的 Command.cs 中,我说明了单击按钮后的功能。与其显示“Hello World”,不如打开我的 winForm。

有什么办法吗?我需要以某种方式 link 我的 winForm 应用程序到这个吗?

namespace SetElevation
{
    [Transaction(TransactionMode.Manual)]
    class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            TaskDialog.Show("SetElevation", "Hello World!");
            return Result.Succeeded;
        }
    }
}

这是我的 winForm Program.cs 应用程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormTest
{
    static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

欢迎使用 Revit 插件开发。你很接近。 我假设如果你让你的插件在上面工作,它正在编译为一个 DLL,而不是一个独立的 EXE。您的 Winform 应用程序似乎是一个单独的 EXE 应用程序。

要完成这项工作,您需要将 Form1 添加到 DLL 项目中。一旦你把它放在那里,你可以改变 TaskDialog.Show 来代替这两行:

var myForm - new Form1(); myForm.ShowDialog();

有了这些,你就上路了。