Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What is the proper way to commit incremental changes to Revit 2013 and 2014?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
rwelchKT
508 Views, 4 Replies

What is the proper way to commit incremental changes to Revit 2013 and 2014?

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;

  }

}

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: rwelchKT

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.

Message 3 of 5
rwelchKT
in reply to: Anonymous

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

 

http://forums.autodesk.com/t5/Autodesk-Revit-API/Start-transaction-not-working-with-Revit-2014/td-p/...

 

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

 

 

Message 4 of 5
Anonymous
in reply to: rwelchKT

Ah. I see...I tried to call a transaction before outside of main thread, but ended up refactoring the code to work a different way. I didn't need to leave the form open to call/finish the transaction. Have you tried moving your Transaction to its own method inside of your IExternalCommand and calling that from the form while leaving it open? That way the transaction stays within the 'Revit thread'?
Message 5 of 5
rwelchKT
in reply to: rwelchKT

Brilliant! That did the trick. Thanks, kmorin!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community