Message 1 of 11
Having Issues with DB.SaveAs()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am able to .Commit() but my .SaveAs keeps failing. I am thinknig it could be due to functions running before this that is causing the issue, but I am at a loss. I am opening Databases and reading DWG files, and for some reason I am feeling as if I am not "Closing" them in other functions previously to this, causing the SaveAs error. It feels odd though since I am able to Save ass this file in a previous function, but in this function, it is unsuccessful.
private void VPFreezeLayerInAllViewportsExceptCurrent(Dictionary<string, LayerTableRecord> LayersToManipulate, string FileName, string MainSheet, string RSSheet)
{
var originalDB = HostApplicationServices.WorkingDatabase;
// Open the drawing
Database database = new Database(false, true);
database.ReadDwgFile(FileName, FileOpenMode.OpenForReadAndAllShare, true, "");
database.CloseInput(true);
HostApplicationServices.WorkingDatabase = database;
using (Transaction tr = database.TransactionManager.StartTransaction())
{
// Get the Layout Dictionary and Layer Table
DBDictionary layoutDict = tr.GetObject(database.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
LayerTable layerTable = (LayerTable)tr.GetObject(database.LayerTableId, OpenMode.ForRead);
IEnumerator<ObjectId> LayersToFreeze = DictionaryToIEnumerator(LayersToManipulate);
// Loop through the Layouts
foreach (DBDictionaryEntry layoutIDs in layoutDict)
{
Layout layout = tr.GetObject(layoutIDs.Value, OpenMode.ForRead) as Layout;
// Once you land on the Main Sheet or RSSheet
if (layout.LayoutName != MainSheet && layout.LayoutName != RSSheet && layout.LayoutName != "Model")
{
// Get the Viewports via the LayoutsBlock Table
BlockTableRecord LayoutBlockTableRecord = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in LayoutBlockTableRecord)
{
Viewport viewport = tr.GetObject(id, OpenMode.ForRead) as Viewport;
if (viewport != null)
{
viewport.UpgradeOpen();
viewport.FreezeLayersInViewport(LayersToFreeze);
LayersToFreeze = DictionaryToIEnumerator(LayersToManipulate);
}
}
}
}
tr.Commit();
database.SaveAs(FileName, DwgVersion.Current);
}
HostApplicationServices.WorkingDatabase = originalDB;
}
There might be some questionable code in here since I am just trying to get things to work, and I can optimize it later (HostApplicationServices...).
Any pointers or ideas is highly appreciated.