Message 1 of 2
How to read DWG files directly without running AutoCAD

Not applicable
11-27-2019
05:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have encountered the following problems in practical work: users do not want to open AutoCAD for operation, but just want to read the data in the DWG file.
After we reference the API, the code is written and compiled, but the object created by the API class will cause system.invalidprogramexception
The specific code is as follows:
Autodesk.AutoCAD.DatabaseServices.Database database = new Autodesk.AutoCAD.DatabaseServices.Database ( false , true );
string dwgFilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "now.dwg";
database.ReadDwgFile ( dwgFilePath , Autodesk.AutoCAD.DatabaseServices.FileOpenMode.OpenForReadAndAllShare , false , "" );
database.CloseInput ( true );
Transaction transaction = database.TransactionManager.StartTransaction ( );