如何在button_click事件中引用Revit API中的文档和应用程序?

时间:2014-05-20 02:46:09

标签: c# api object document revit

这是显示在revit api中获取的对象的execute方法,接下来是相关代码。无法获取对文档或应用程序对象的引用,这是我从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);
    }

1 个答案:

答案 0 :(得分:1)

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

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