Given that Revit 2014 no longer supports nested transactions, is the following an approved approach for committing extensible storage data to Revit in versions 2013 and 2014?
Cheers,
Ryan Welch
private void saveToExtensibleStorage(Element element)
{
try
{
switch (app.VersionNumber)
{
case "2013":
Transaction trans = new Transaction(doc);
trans.Start();
if (mySaveExtensibleStorageMethod(element)) trans.Commit();
else trans.RollBack();
trans.Dispose();
break;
case "2014":
SubTransaction subtrans = new SubTransaction(doc);
subtrans.Start();
if (mySaveExtensibleStorageMethod(element)) subtrans.Commit();
else subtrans.RollBack();
subtrans.Dispose();
break;
}
}
catch
{
}
}
private bool mySaveExtensibleStorageMethod(Element elementToSaveTo)
{
try
{
//.... do stuff here
//.... if it works
return true;
}
catch
{
// if it fails
return false;
}
}
Solved! Go to Solution.
Where is your main transaction? My understanding is you must have opened a normal transaction in order to start a SubTrans...also, you must close out your open transaction before you start another Transaction (2013) or else you will get an exception.
My main transaction is an IExternalCommand which calls a System.Windows.Forms.Form as a modeless dialog (where the bulk of my code resides). I am trying to commit incremental changes to the Revit database while my form is still open AND still allow the user to continue to work in the Revit model. It was my understanding from this following post
that the Transaction.Start() method was no longer supported for modeless dialogs in Revit 2014. Hence I am wrapping my modeless dialog in a Transaction, and placing the subtransaction within the System.Windows.Forms.Form class.
Perhaps I'm not clear on the appropriate procedure, but the intent is that I don't have to wait until closing my form to commit what could potentially be a large number of changes all at once.
Cheers,
Ryan Welch