C# Revit API - 如何从 autocad 文件中提取信息

问题描述:

过去一个月我一直在努力解决这个问题,并试图获得最终的联系.

I've been working on this for the past month and am trying to get the final connection.

到目前为止,我可以打开 Revit,从 Revit 按钮执行 Autocad DLL,但是我不知道如何将信息拉回 Revit API.我尝试了几种不同的方法,但是我遇到了困难.以下是我尝试过的选项,并在下面进行了解释

so far, I can open Revit, execute an Autocad DLL from a Revit button however I don't know how to pull the information back into the Revit API. I have tried a couple of different methods however I've come to a wall. Here are the options I've tried with explanations below

1) 使用类将 DLL 文件和 Revit Button API 文件合二为一.---> 在加载现有的 CAD 文件时,尝试这种方法会让我出错.如果我正在创建一个新的 CAD 文件,或者如果我在 Autocad 设置为调试的情况下单独运行 DLL,我不会收到此错误.

1) Combine the DLL file and the Revit Button API file into one using classes. ---> Trying this method leaves me with an error when loading an existing CAD file. I don't get this error if I'm creating a new CAD file or if I'm running the DLL by itself with Autocad set to Debug.

Grabbing CAD file failed. 
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

e.StackTrace: 
   at AcDbDatabase.{ctor}(AcDbDatabase* , Boolean , Boolean )
   at Autodesk.AutoCAD.DatabaseServices.Database..ctor(Boolean buildDefaultDrawing, Boolean noDocument)
   at CAD2Revit.AutoCadOperations.grabCAD(String filepath)
   at CAD2Revit.Command.Execute(ExternalCommandData commandData, String& message, ElementSet elements)

尝试运行此行时:

// Create a database and try to load the file
Autodesk.AutoCAD.DatabaseServices.Database db = new Database(false, true); // error occuring here often

我对错误做了一些研究,这是唯一的关闭仓库

I've done some research on the error and this is the only close repoo

2) 将它们分开--> 在这个选项中,我已经弄清楚了如何以编程方式打开 AutoCAD,netload 一个 DLL,然后执行它来获取文件信息,但我无法将信息返回到 Revit API

2) Keep them separate --> In this option, I've figured out how programatticly open AutoCAD, netload a DLL, and then execute it which grabs the file information but then I cant return the info to the Revit API

对于如何解决这个问题的任何智慧或建议表示赞赏.

Any wisdom or advice is appreciated on how to approach this.

这是我见过的与此类似的最接近的帖子,但我认为它在 VB 中并且超出了我的理解.https://forums.autodesk.com/t5/net/system-accessviolationexception-attempted-to-read-or-write/td-p/4796397

this is the closest post i've seen similar to this but its in VB i think and is over my head. https://forums.autodesk.com/t5/net/system-accessviolationexception-attempted-to-read-or-write/td-p/4796397

我看不出为什么会出现这样的问题.如果一切都失败了,你总是可以 使用IPC 将两个进程分开.但是,实际上不应该有任何需要.

I see no reason why such a problem should appear. If all else fails, you could always use IPC to separate the two processes. However, there should not really be any need for this.