【问题标题】:How To Reference Document and Application from Revit API in a button_click event?如何在 button_click 事件中从 Revit API 引用文档和应用程序?
【发布时间】:2014-05-20 02:46:09
【问题描述】:

这是显示在 revit api 中获得的对象的执行方法,下面是有问题的代码。无法获得对文档或应用程序对象的引用,这是我从 ms visual stud 中的错误报告中收集到的。 我试过添加一个全局参考,即。文档文件;与其他全局变量一起但是这并没有修改无参考错误。

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //获取应用程序和文档对象 UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument;

        try
        {
            Application app = uiApp.Application;
            Document doc = uiDoc.Document;

         ...  rest of code not included   


      //mouse button click event
    public void btn1_Click(object sender, EventArgs e)
    {
        //call to method using the Document doc revit api handle
        MethodThatRequiresDoc(doc);
    }


    MethodThatRequiresDoc(Document doc);
    {

   //Call to copy and paste between docs new revit 2014 method
        CopyPasteMassesBetweenDocs(doc, app);
    }

【问题讨论】:

    标签: c# api object document revit


    【解决方案1】:

    查看ExternalEvents framework 的文档。基本上,您不会在btn1_Click 事件处理程序中获得Document 实例。相反,您提出一个ExternalEvent,调用的处理程序的签名将包含对Document 的引用。

    Jeremy Tammik 的这篇博文可能会有所帮助:http://thebuildingcoder.typepad.com/blog/2013/12/replacing-an-idling-event-handler-by-an-external-event.html

    【讨论】:

    • 这对你有很大帮助,谢谢。
    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2013-04-11
    • 2016-12-28
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多