Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there anything wrong with this code? It is called in a loop with changing filenames. AT the very end AutoCAD crashes.
public Substituter (string sOldString, string sNewString, string sSourceFullFileName, string sDestFullPath) { // The name won't change but the directory will string sNameOnly = Path.GetFileName(sSourceFullFileName); // Save as a new file string sFullDestFileName = sDestFullPath + @"\" + sNameOnly; using (Database db = new Database(false, true)) { db.ReadDwgFile(sSourceFullFileName, FileOpenMode.OpenForReadAndWriteNoShare, false, ""); // closing the input makes sure the whole dwg is read from disk // it also closes the file so you can SaveAs the same name db.CloseInput(true); // store the current working database, to reset Database PreviousDb = HostApplicationServices.WorkingDatabase; // set working database HostApplicationServices.WorkingDatabase = db; // { Do Some Work}
// Take this out and there is no crash... db.SaveAs(sFullDestFileName, DwgVersion.Current); // reset the working database HostApplicationServices.WorkingDatabase = PreviousDb; } }
It creates the files and then crashes at the end. If I don't call SaveAs it does not crash. What am I missing? The SaveAs apparently works though...!
Solved! Go to Solution.