我一直在尝试使用 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/