Community
I am trying to write some code that opens a DWG from within a Revit add-in (Revit 2021, AutoCAD 2017 and VS 2019). Once the DWG file is opened, certain layers will be turned off before the file is imported to Revit. The Open command throws an exception: "Method not available in MDI mode. Use Open method of Documents collection". Thank you in advance for your help and expertise.
[TransactionAttribute(TransactionMode.Manual)]
public class OpenDWG : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Autodesk.AutoCAD.Interop.AcadApplication app = new Autodesk.AutoCAD.Interop.AcadApplication();
Autodesk.AutoCAD.Interop.AcadDocument adoc = app.Documents.Application.ActiveDocument;
string pfile = "C:\\Testfile.dwg";
adoc.Open(pfile); //this command throws an exception
//add more code here to turn off unwanted layers
adoc.Save();
app.Quit();
return Result.Succeeded;
}
}
Thank you for the query.
This approach makes total sense to me.
Unfortunately, though, this forum is dedicated to the pure Revit API.
I suggest you address this query to the AutoCAD.NET customisation forum instead:
https://forums.autodesk.com/t5/net/bd-p/152
Can't find what you're looking for? Ask the community or share your knowledge.