问题
I've been working on this for the past month and am trying to get the final connection.
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) 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)
when trying to run this line:
// 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) 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.
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
回答1:
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.
来源:https://stackoverflow.com/questions/60385727/c-sharp-revit-api-how-to-pull-info-from-autocad-file