problem reading in dxf/dwg files

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello everyone,
i am developing some code to read in mass dxf OR dwg files, seperate the two, then convert each to a database to be read later. however, whenever i run it, i get this error:
System.AccessViolationException: Attempted to read or write protected memory. this is often an indication that other memory is corrupt.
at AcDbDatabase.dxfIn(AcDbDatabase*, Char*, Char*)
at Autodesk.AutoCAD.DatabaseServices.Database.DxfIn(String fileName, String logFilename)
at ZahnerCommands.Commands.GetFiles()....line 72
here is the code that i have so far. i have been tinkering around with it for a few days and cannot seem to get it to work. the dxf file i have chosen works perfectly well, and i am using autocad 2011. thank you for all of your help
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.DatabaseServices;
using
Autodesk.AutoCAD.EditorInput;
using
Autodesk.AutoCAD.Runtime;
using
System.Runtime.InteropServices;
using
Autodesk.AutoCAD.Interop;
using
Autodesk.AutoCAD.Interop.Common;
....
publicvoid GetFiles()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage(
"\nChoose an input folder");
inFolderPath = ChooseFolder();
dwgFilePaths =
Directory.GetFiles(inFolderPath, "*.dwg");
dxfFilePaths =
Directory.GetFiles(inFolderPath, "*.dxf");
// Converts to dxf files into readable databases. refer to the transaction manager to read specific info
dxfInfo =
new Database[dxfFilePaths.Length];
for (int i = 0; i < dxfFilePaths.Length; i++)
{
string tempFile = inFolderPath + "\\" + (i+1) + "TEMPLOG.txt";
try
{
using (File.CreateText(tempFile))
{
dxfInfo[i] =
new Database(false, true);
using (dxfInfo[i])
{
try
{
dxfInfo[i].DxfIn(dxfFilePaths[i], tempFile);
//Autodesk.AutoCAD.DatabaseServices. perhaps? this is line 72
}
catch (System.Exception wx)
{
MessageBox.Show("Unable to read the " + (i + 1) + " file. Check TEMPLOG.txt and\n" +wx, "Can't Read File", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
catch // this was to catch for any old dxf files; i got the idea from kean's blog
{
dxfInfo[i] =
new Database(true, false);
using (dxfInfo[i])
{
try
{
dxfInfo[i].DxfIn(dxfFilePaths[i], tempFile);
}
catch (System.Exception wx)
{
MessageBox.Show("Unable to read the " + (i+1) + " file. Check TEMPLOG.txt, and\n" +wx, "Can't Read File", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
if there is anything else i can provide please let me know. i am at my wits end trying to figure out what is wrong.
ps: if this is the wrong section please direct me to the correct one.