Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open DWG using Revit API

1 REPLY 1
Reply
Message 1 of 2
dengebre
1174 Views, 1 Reply

Open DWG using Revit API

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;
    }
}

 

Tags (2)
Labels (2)
1 REPLY 1
Message 2 of 2
jeremytammik
in reply to: dengebre

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report