transaction usage, need best practice advice

transaction usage, need best practice advice

luc.vallotP8MJ4
Contributor Contributor
673 Views
3 Replies
Message 1 of 4

transaction usage, need best practice advice

luc.vallotP8MJ4
Contributor
Contributor

Hello,

 

I'm working on a big plugin, it create many viewplan,3dview,textnotes,filledregions, ...,
reread them, export them, and so...
it work on very large models

 

and I need your advice


what are the best practices (in term of revit efficacity) ?

 

have one big transaction and all of the code inside ?

have one transaction per creation/modification functions (actually 1 function per object) ?

have some well chosen transactions (for update grouping) ?

have one transaction and many subtransactions ?

other solution ?

 

thanks in advance

 

Luc

0 Likes
674 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @luc.vallotP8MJ4 ,

I would suggest you go for one transaction and many subtransactions.

Subtransaction is to control a set of modifications done in a transaction, meaning that the modification enclosed in a sub-transaction can be rolled back as if they have not happened. In a sense, it allows an application to go back to a certain point (the start of the sub-transaction) in a sequence of model changes.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

luc.vallotP8MJ4
Contributor
Contributor

Hi Naveen,

I understand the logic in term of commit/rollback
but
is it a difference in term of revit execution speed ?
is it a difference in term of regeneration need ?

Luc

0 Likes
Message 4 of 4

jlpgy
Advocate
Advocate

As far as I have experienced, SubTransactions comsume nearly all the same processing time.

I had tried Rollback() very simple commit, as well as very complicated commit, and found out that the time of rolling back sub-transactions are almost the same.

The above mentioned info leads easily to one conclusion: Start a Transaction at the TOP-LEVEL of your ExternalCommand or ExternalEvent or Idling event handler, use as many SubTransactions as you like to manage your "sub tasks".

For example:

  • You might want to delete an Element 1
  • You are not sure if another Element 2 is gonna be deleted because of deleting Element 1
  • If Element 2 is deleted, you might want to roll back, and find other elements to delete (or not delete anything at all)

In the above mentioned circumstance

  1. Start a Transaction in your External Command
  2. Start a SubTransaction
  3. Delete Element1
  4. Check if Element 2 is also deleted
  5. If Elem 2 is deleted, then roll back sub transaction (don't worry about the time comsuming)

😁Hope this helps, Nice coding.

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes