I've been working on a rendering engine that uses AutoCAD 2025 using .Net 8 and only requires Acdbmgd.dll. I create a new Database object, read in an existing template, add entities to it and then save it. It all works as I intended, but then I ran into some problems with the saved drawing that required me to run an audit. The audit returned numerous errors:
Auditing Header
Auditing Tables
Auditing Entities Pass 1
AcDbLayerTableRecord: "0"
Material Invalid Global
AcDbLayerTableRecord: "0" was not repaired.
Pass 1 100 objects audited
Auditing Entities Pass 2
AcDbLayerTableRecord: "0"
Material Invalid Global
AcDbLayerTableRecord: "0" was not repaired.
AcDbDictionary(99) 2dWireframe eNotThatKindOfClass
AcDbDictionary(99) Basic eNotThatKindOfClass
AcDbDictionary(99) Brighten eNotThatKindOfClass
AcDbDictionary(99) ColorChange eNotThatKindOfClass
AcDbDictionary(99) Conceptual eNotThatKindOfClass
AcDbDictionary(99) Dim eNotThatKindOfClass
AcDbDictionary(99) EdgeColorOff eNotThatKindOfClass
AcDbDictionary(99) Facepattern eNotThatKindOfClass
AcDbDictionary(99) Flat eNotThatKindOfClass
AcDbDictionary(99) FlatWithEdges eNotThatKindOfClass
AcDbDictionary(99) Gouraud eNotThatKindOfClass
AcDbDictionary(99)
GouraudWithEdges eNotThatKindOfClass
AcDbDictionary(99) Hidden eNotThatKindOfClass
AcDbDictionary(99) JitterOff eNotThatKindOfClass
AcDbDictionary(99) Linepattern eNotThatKindOfClass
AcDbDictionary(99) OverhangOff eNotThatKindOfClass
AcDbDictionary(99) Realistic eNotThatKindOfClass
AcDbDictionary(99) Shaded eNotThatKindOfClass
AcDbDictionary(99)
Shaded with edges eNotThatKindOfClass
AcDbDictionary(99) Shades of Gray eNotThatKindOfClass
AcDbDictionary(99) Sketchy eNotThatKindOfClass
AcDbDictionary(99) Thicken eNotThatKindOfClass
AcDbDictionary(99) Wireframe eNotThatKindOfClass
AcDbDictionary(99) X-Ray eNotThatKindOfClass
AcDbDictionary(99) was not repaired.
Pass 2 100 objects audited
Auditing Blocks
1 Blocks audited
Auditing AcDsRecords
Total errors found 26 fixed 0
I was able to simplify the code and "wrap it" in a plugin to show the behavior and the results are the same:
public class Plugin : IExtensionApplication
{
public void Initialize() { }
public void Terminate() { }
[CommandMethod("Test")]
public void Test()
{
Database db;
using (db = new Database(true, false))
{
try
{
string currentFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
db.ReadDwgFile($"{currentFolder}\\test_clean.dwg", FileOpenMode.OpenTryForReadShare, true, null);
db.SaveAs(@"c:\temp\test_clean.dwg", DwgVersion.Current);
db.DxfOut(@"c:\temp\test_clean.dxf", 16, DwgVersion.Current);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Note that the input drawing, "test_clean.dwg" is truly clean. It is a brand new, empty drawing saved just for use in this test. Both output files produce the same audit errors.
This happens in AutoCAD 2025 using .Net 8 and AutoCAD 2024 with .Net Framework 4.7.2
Has anyone run into this before? Any help would be greatly appreciated!
When creating a new Database to use ReadDwgFile, the arguments in the Database ctor should be: buildDefaultDrawing = false and noDocument = true.
[CommandMethod("Test")]
public static void Test()
{
using (Database db = new Database(false, true))
{
try
{
string currentFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
db.ReadDwgFile($"{currentFolder}\\test_clean.dwg", FileOpenMode.OpenForReadAndAllShare, true, null);
db.SaveAs(@"c:\temp\test_clean.dwg", DwgVersion.Current);
db.DxfOut(@"c:\temp\test_clean.dxf", 16, DwgVersion.Current);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}