We are getting an error (see attached image) using RealDWG 2013 on this test function below note the same code as-is works in RealDWG 2009 - the DW1645ASY.dwg it is a drawing made of 3D solids, if we try this with a drawing without 3D solids sometimes it will work and others not - Any ideas? or Help that I can get about this? - Thanks:
public static void Draw(string outputFile)
{
string acadTemplateFile = @"C:\hotfiles\CAD_Templates\Common\acad.dwt";
using (Host host = new Host())
{
using (Autodesk.AutoCAD.DatabaseServices.Database db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
{
File.Copy(acadTemplateFile, outputFile, false);
db.ReadDwgFile(outputFile, System.IO.FileShare.ReadWrite, false, null);
HostApplicationServices.WorkingDatabase = db;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord iModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
ObjectId blockId = ObjectId.Null;
using (Transaction tran = db.TransactionManager.StartTransaction())
{
using (Autodesk.AutoCAD.DatabaseServices.Database sdb = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
{
string file = @"C:\hotfiles\CAD_Templates\Ductwork\3D\Elbow 45\DW1645ASY.dwg";
sdb.ReadDwgFile(file, System.IO.FileShare.ReadWrite, false, "");
blockId = db.Insert(file, sdb, true);
}
HostApplicationServices.WorkingDatabase = db;
tran.Commit();
}
BlockReference blockRef = new BlockReference(Point3d.Origin, blockId);
iModelSpace.AppendEntity(blockRef);
tr.AddNewlyCreatedDBObject(blockRef, true);
tr.Commit();
}
db.SaveAs(outputFile, DwgVersion.AC1015);
}
}
}