- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok, I know this is another null reference question, but I've checked the forums and google and can't come up with a solution to my particular problem.
I have a function that loops through all of the sheets in a sheet set and updates the description of each. When I lock the database to make the changes to the description I have no problem. When I check the lock status of the database after the LockDB() method it says Locked_Local. Everything looks fine until after I make the change to the description and try to unlock the database and commit my changes. When the database.UnlockDb() statement executes I get a null reference exception. It makes no sense as I'm not changing the database.
What is confusing to me is I have another command that modifies the sheet properties in a similar way and that command doesn't have any issues locking and unlocking the database. I am getting the database in the same manner but for some reason this method doesn't work.
What am I doing wrong?
I have created a couple of helper functions to pull sheets from the sheet set manager and to lock/unlock the database. All of my code is below.
private static bool LockDatabase(AcSmDatabase database, bool lockFlag)
{
bool dbLock = false;
if (lockFlag == true && database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_UnLocked)
{
database.LockDb(database);
dbLock = true;
}
if (lockFlag == false && database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_Locked_Local)
{
database.UnlockDb(database, true); // This is where I get the exception
dbLock = true;
}
return dbLock;
}
public static void Test()
{
try
{
Document doc = acApp.DocumentManager.MdiActiveDocument;
using (Transaction tran = doc.TransactionManager.StartTransaction())
{
string description = "\n";
List<AcSmSheet> sheets = GetSheets();
foreach (AcSmSheet sheet in sheets)
{
AcSmDatabase database = sheet.GetDatabase();
if (LockDatabase(database, true) == true)
{
AcSmCustomPropertyValue value = GetSheetCustomValue(sheet, "SheetTitle1");
description = description + " " + value.GetValue().ToString();
value.Clear();
value = GetSheetCustomValue(sheet, "SheetTitle2");
description = description + " " + value.GetValue().ToString();
value.Clear();
value = GetSheetCustomValue(sheet, "SheetTitle3");
description = description + " " + value.GetValue().ToString();
value.Clear();
value = GetSheetCustomValue(sheet, "SheetTitle4");
description = description + " " + value.GetValue().ToString();
value.Clear();
doc.Editor.WriteMessage(description);
sheet.SetDesc(description);
description = "\n";
LockDatabase(database, false);
}
}
tran.Commit();
}
}
catch (System.Exception e)
{
acApp.ShowAlertDialog(e.Message);
}
}
Solved! Go to Solution.