Page 1 of 1
[Solved] Combine Multiple Transactions Into One
Posted: Wed Dec 18, 2024 6:41 am
by 333onlyhalfevil
Hello everyone:
Is there any way to combine multiple document transactions into one? I have a script that is (1) creating a block, (2) adding objects to the block, and (3) modifying the block to add in some custom properties. The script works but the problem is that I have to hit the back button 3x in order to undo everything. Is there any way to combine these three transactions into a single transaction so all 3 happen in just one operation?
Thank you very much for your help.
Re: Combine Multiple Transactions Into One
Posted: Wed Dec 18, 2024 7:43 am
by CVH
Hi,
Yes, with a
transaction group but there are counter indications.
- Layers must exists before you can cast entities on them.
- An entity or a Block must have an id before you can re-query it.
- ....
Sometimes there is no way around.
For example: Adding a layer requires 2 steps to undo.
- Undo set current
- Undo creation
2, 3 ... or much more steps to Undo (
OO) the last GUI action is not at all strange.
If it is an option ...
It is probably more interesting to complete all actions on the virtual objects before casting them.
The same advice as in
this topic
Code: Select all
// Start a new transaction group
doc.startTransactionGroup();
// First operation
var op = new RAddObjectsOperation();
op.setTransactionGroup(doc.getTransactionGroup());
...
op.addObject(...);
op.addObject(...);
di.applyOperation(op);
// Second operation
op = new RAddObjectsOperation();
op.setTransactionGroup(doc.getTransactionGroup());
...
op.addObject(...);
di.applyOperation(op);
Or automatically within a limited section:
Code: Select all
doc.startTransactionGroup();
// Add all operations to the current transaction group:
doc.setAutoTransactionGroup(true);
....
..
.
doc.setAutoTransactionGroup(false);
Regards,
CVH
Re: Combine Multiple Transactions Into One
Posted: Wed Jan 08, 2025 2:38 am
by 333onlyhalfevil
This seems to work as expected. Thank you.
Re: Combine Multiple Transactions Into One
Posted: Wed Jan 08, 2025 3:55 pm
by 333onlyhalfevil
How would you recommend I force the start of a new transaction group?
Re: Combine Multiple Transactions Into One
Posted: Wed Jan 08, 2025 6:56 pm
by CVH
333onlyhalfevil wrote: ↑Wed Jan 08, 2025 3:55 pm
How would you recommend I force the start of a new transaction group?
Never really thought about it further ...
Neither the reference nor existing usage makes any mention of:
- That
doc.startTransactionGroup(); starts a
new group.
- What ends it.
The only refernece to
new is
this answer by Andrew.
I suspect it is as simply as starting a 'new' transaction group.
But then the former group becomes obsolete in the meaning of out of the picture or finished I think.
Regards,
CVH
Re: Combine Multiple Transactions Into One
Posted: Thu Jan 09, 2025 1:08 am
by 333onlyhalfevil
That seems like it might be the case in general. All but one of my scripts are registering as separate transaction groups using doc.startTransactionGroup() at the beginning. The one that is giving problems is a sole RModifyObjectsOperation() that gets grouped together with the previous transaction group even though it has the doc.startTransactionGroup() at the beginning.
Re: Combine Multiple Transactions Into One
Posted: Thu Jan 09, 2025 5:09 am
by CVH
333onlyhalfevil wrote: ↑Thu Jan 09, 2025 1:08 am
All but one of my scripts ... The
one that is giving problems
With "all" and "one" I have too little info to help you further.
Perhaps you could contact me per PM and share the scripts and required resources like example files if that is necessary.
Everything will be treated with utmost confidentiality.
Any copy will be deleted afterwards.
What you attach at a PM (or any topic) can be deleted at your side.
Regards,
CVH
Re: Combine Multiple Transactions Into One
Posted: Thu Jan 09, 2025 8:12 am
by CVH
Tinkering further ...
I expect that the explicit method with
op.setTransactionGroup(doc.getTransactionGroup()); uses the current group.
From the
reference: Calling
startTransactionGroup(); does nothing more than increasing the
lastTransactionGroup counter.
And
getTransactionGroup() returns that counter value. (A few lines lower)
Then it might be the order of thing, or simply some points and commas ...
Or don't mix the explicit and the auto assignment method.
Also, don't forget to stop the auto assignment method.
Probably mandatory before you start a new group ... With or without auto assignment.
In the light of that:
What does the following do:
Code: Select all
// Ifso, stop auto grouping:
if (doc.getAutoTransactionGroup()) {
doc.setAutoTransactionGroup (false);
}
// Start a new transaction group
doc.startTransactionGroup();
// Problematic operation
var op = new RModifyObjectsOperation();
op.setTransactionGroup(doc.getTransactionGroup());
...
di.applyOperation(op);
// Back to other script;
return;
I also think that you can't stack it ....
- Code A with group 1
Code A calls Code B and there you want it to be group 2
Back to A, still using group 1
Regards,
CVH
Re: Combine Multiple Transactions Into One
Posted: Sat Jan 11, 2025 9:09 pm
by 333onlyhalfevil
The code in the code block doesn't change anything.
CVH wrote: ↑Thu Jan 09, 2025 8:12 am
I also think that you can't stack it ....
- Code A with group 1
Code A calls Code B and there you want it to be group 2
Back to A, still using group 1
This seems to be the case. I can get it to be a separate transaction by simply adding in a random entity with an RAddObjectsOperation.
Anyways, thank you very much for your help. I'll mark this one as solved.