gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:05:10 25 4
gpt4 key购买 nike

我一直在尝试使用带有 Windows 窗体的 Visual Studio 2015 为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com