c# - 初始化 Win。来自 Revit 按钮和执行命令的表单
问题描述
任何人都可以告诉我如何(如果可能的话)实现一个我已经编写的类,按下 Revit 插件功能区中的按钮时显示的表单中的按钮?附件是我到目前为止所取得的图像的链接。
我在 Visual Studio 中使用 C# 语言实现 ExternalApplication 类。
谢谢
namespace PEASA_TOOLS_2021
{
public class PEASA_TOOLS_2021 : IExternalApplication
{
static void AddRibbonPanel(UIControlledApplication application)
{
//Create panel
RibbonPanel ribbonPannel4 = application.CreateRibbonPanel(tabName, "Pruebas");
//Button for execute Form.
PushButtonData pbFormdata = new
PushButtonData("cmdFormData","Extracción de Data", thisAssemblyPath, "PEASA_TOOLS_2021.DATA_EXTRACTION.DataExtractionButton");
PushButton pbForm = ribbonPannel4.AddItem(pbFormdata) as PushButton;
BitmapImage pruebasImage = new BitmapImage(new Uri("pack://application:,,,/PEASA_TOOLS_2021;component/RECURSOS/PRUEBAS.png"));
pbForm.LargeImage = pruebasImage;
}
}
}
解决方案
我去过那里,我知道你的挣扎。这是我到目前为止所做的,它对我有用,它可能不是最好的解决方案,但它是我唯一的解决方案。
首先,您需要将这些变量添加到 Form 的部分类中
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public partial class Form1 : System.Windows.Forms.Form
{
private UIApplication uiapp;
private UIDocument uidoc;
private Document doc;
private ExternalCommandData commandData;
private string message;
private ElementSet elements;
然后,您必须将表单构造函数编辑为如下所示:
public Form1(ExternalCommandData commandData,ref string message, ElementSet elements)
{
InitializeComponent();
this.commandData = commandData;
this.elements = elements;
uiapp = commandData.Application;
uidoc = uiapp.ActiveUIDocument;
doc = uidoc.Document;
}
然后,您将在 Form 部分类下创建一个函数,该函数就是您在其中编写命令的函数:
它会是这样的:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
write your code here
return Result.Succeeded;
}
那么您只需调用 Button1_Click 函数下的执行函数
protected internal void Button1_Click(object sender, EventArgs e)
{
Execute(commandData, ref message, elements);
}
现在对于在按下 PushButton 后调用 Form 的类:
Class DataExtractionButton : IExternalCommand
{
public Result Execute (ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
ExternalCommandData revit = commandData;
var window = new Form1(commandData, ref message, elements);
window.ShowDialog();
return Result.Succeeded;
}
}
这应该是这样做的方法。
我希望这可以帮助你,它适用于我的情况。
推荐阅读
- javascript - 如何在单个过滤器中创建多个条件
- php - 如何在 laravel 中访问两个中间件的多条路由
- python - 如何将数据框的字典(存储为值)转换为一个 CSV?
- c# - 如何从正在创建/调用的类中提取构造函数的参数?- C#
- reactjs - 在 react 中使用 useState 钩子时设置后读取组件状态
- python - 需要同时运行2个函数,但是它们只能一个接一个地运行
- android - 如何从应用程序内部关闭应用程序通知
- jquery - 如何自动化不同复选框的直接输出?
- css - 使底部表(弹出窗口)粘在按钮上(角材料)
- python-3.x - Pandas Dataframe 到 sql 表需要帮助: