Sub-transactions among multiple documents

Sub-transactions among multiple documents

jnoordzij
Advocate Advocate
608 Views
2 Replies
Message 1 of 3

Sub-transactions among multiple documents

jnoordzij
Advocate
Advocate

My question is about sub transactions. 

 

I have designed an add-in that does something like the following:

-start transaction in doc

-make some changes

-scan the doc for placed family instances

-for each found family instance:

    -go inside that family

    -start transaction inside family

    -make some changes

    -scan the inside of the family for nested family instances 

    -for each found nested family

        -go inside that nested family

        -start transaction inside nested family

        -make some changes

        -commit transaction inside nested family

        -load nested family back into family

    -commit transaction inside family

    -load family back into document

-commit transaction in doc

 

The way I have it now, is that all those transactions are separate transactions. So after the command is run, a whole bunch of commands appear under the undo-command button.  However I would like to be able to undo this command with 1 press of the undo button

 

I was thinking to use sub-transactions for this. But I was wondering if sub-transactions always have to be inside the same doc, or can it be among multiple docs, like in my example?

 

Furthermore I am struggling to find a good piece of example-code on sub-transactions. I found this, but I am not sure if I can use it, considering that the example executes on the same doc.

 

So my question is: How would the syntax about the main-transaction and sub-transactions be, based on the above example?

 

Thanks in advance. 

0 Likes
609 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Good question!

 

The TransactionGroup constructor takes the document as an argument:

 

https://apidocs.co/apps/revit/2019/74cff3fa-9380-2c30-9fa9-b0e839a2c8e4.htm

 

All sub-transactions it contains can process only that specific document.

 

You could start a new transaction group for each document you process.

 

However, I do not see how you could implement what you are doing using less transaction groups than the number of documents processed.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

jnoordzij
Advocate
Advocate

Thanks, Jeremy. 

0 Likes