c# - 使用 Windows 窗体创建 Revit 插件

标签 c# winforms revit-api revit

我一直在尝试使用 Visual Studio 2015 和 Windows Form 创建 Revit 2017 插件。 不幸的是,我没有在网上找到任何这样做的文档(如果您有链接,我很乐意给他们看一下)

我使用列表框和选择按钮构建了一个简单的表单

  • 列表框显示 Revit 项目中的所有门
  • 选择按钮会从列表框中选择所有选定的门,并在 Revit 项目中选择它们(有很多选择...)

这是一个测试解决方案,旨在了解其工作原理。

WeWillSee 类是实现主要 RevitAPI 函数的类 执行:

 using System; 
 using Autodesk.Revit.UI; 
 using Autodesk.Revit.Attributes; 
 using Autodesk.Revit.DB;

 namespace Test2 {

 [Transaction(TransactionMode.Manual)]
 class WeWillSee : IExternalCommand
 {
     public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
     {
         UIApplication uiapp = commandData.Application;
         /*UIDocument uidoc = uiapp.ActiveUIDocument;
         Document doc = uidoc.Document;*/

         try
         {
             System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
             System.Windows.Forms.Application.Run(new Form(commandData));
             //System.Windows.Forms.Form wf = new Form1(uiapp);
         }
         catch (Exception e)
         {
             TaskDialog.Show("Error", e.ToString());
             return Result.Failed;
         }

         return Result.Succeeded;
     }
 } 
 }

我要打开的表单(其余的不重要):

namespace Test2
{
    public partial class Form : System.Windows.Forms.Form
    {
        private UIApplication uiapp;
        private UIDocument uidoc;
        private Document doc;

        public Form(ExternalCommandData commandData)
        {
            InitializeComponent();

            uiapp = commandData.Application;
            uidoc = uiapp.ActiveUIDocument;
            doc = uidoc.Document;
        }

最后是 Program.cs 文件(导致我出现问题的文件):

namespace Test2
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(/*Can't call ExternalCommandData on static class*/));
        }
    }
}

感谢您提供的任何帮助! :)

最佳答案

我认为您甚至不需要按照您编写的方式在项目中使用 Program.cs 类文件。

关于c# - 使用 Windows 窗体创建 Revit 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41504640/

相关文章:

c# - CheckBoxFor 的 MVC 3 自定义 ValidationAttribute 在客户端触发两次

c# - 工具提示中的超链接

autodesk-forge - 如何使用 Forge Design Automation API 将 BIM 360 中的 Revit 文件另存为云模型?

c# - Revit C# 运行代码 "OnShutDown"和 "OnStartup"

c# - 是否有任何框架或实用程序(在 .NET 空间中)用于从业务对象自动生成数据传输对象

c# - 我正在尝试在 C# 应用程序上运行一些 powershell 脚本以授予对 Azure AD 应用程序的权限,它适用于 Powershell,但不适用于 C# 应用程序

vb.net - 每个新的 ClickOnce 部署版本都会丢失 VB.NET "My.Settings"

c# - 为什么当我对行进行更改时 DataRowState 显示已添加而不是已修改?

c# - 无法加载文件或程序集(BadImageFormatException和FileNotFoundException)

c# - 如何在母版页内的用户控件中获取内容页名称?