I've written a program to export DXF files from DWG files. I've used Tony's CaddZone.DatabaseServices.WorkingDatabase code and all seemed to work fine until I found out that the InsBase system variable value of the "db.ReadDwgFile(drawingFile.FullName, FileShare.Read, true, null);" is not what the DWG contains.
The DWG attached has a non-zero based InsBase system variable. When I step through my code below the db.insbase value is always 0,0,0.
Any ideas/suggestions?
try
{
Database db = new Database(false, true);
using (CaddZone.DatabaseServices.WorkingDatabase wdb = new CaddZone.DatabaseServices.WorkingDatabase(db))
{
FileInfo dwl = new FileInfo(drawingFile.FullName.Substring(0, drawingFile.FullName.Length - 3) + "dwl");
if (!dwl.Exists)
{
db.ReadDwgFile(drawingFile.FullName, FileShare.Read, true, null);
if (db != HostApplicationServices.WorkingDatabase)
{
HostApplicationServices.WorkingDatabase = db;
}
db.Insunits = UnitsValue.Undefined;
db.DxfOut(dxfFolder.ToUpper() + "\\" +
drawingFile.Name.Substring(0, drawingFile.Name.Length - 4).ToUpper() +
".dxf",
dwgPrecision,
DwgVersion.AC1800);
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception aex)
{
if (stringBuilder == null)
stringBuilder = new StringBuilder();
if (aex.ErrorStatus == ErrorStatus.FileSharingViolation)
stringBuilder.AppendFormat("\n{0} is already open!", drawingFile);
else if (aex.ErrorStatus == ErrorStatus.DwgNeedsRecovery)
stringBuilder.AppendFormat("\n{0} needs recovery!", drawingFile);
else if (aex.ErrorStatus == ErrorStatus.BadDwgHeader)
stringBuilder.AppendFormat("\n{0} has a bad drawing header!", drawingFile);
else
stringBuilder.AppendFormat("\n{0} has error {1}", drawingFile, aex.Message);
continue;
}
catch (System.Exception ex)
{
acActiveDocEd.WriteMessage("\nError: {0}", ex.Message);
acActiveDocEd.WriteMessage("\nStack trace: {0}", ex.StackTrace);
return;
}
Thanks!
Doug