[Solved] Combine Multiple Transactions Into One
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
-
- Full Member
- Posts: 92
- Joined: Fri Apr 28, 2023 12:39 pm
[Solved] Combine Multiple Transactions Into One
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.
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.
Last edited by 333onlyhalfevil on Sat Jan 11, 2025 9:10 pm, edited 1 time in total.
-
- Premier Member
- Posts: 4889
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Combine Multiple Transactions Into One
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
Or automatically within a limited section:
Regards,
CVH
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);
Code: Select all
doc.startTransactionGroup();
// Add all operations to the current transaction group:
doc.setAutoTransactionGroup(true);
....
..
.
doc.setAutoTransactionGroup(false);
CVH
-
- Full Member
- Posts: 92
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Combine Multiple Transactions Into One
This seems to work as expected. Thank you.
-
- Full Member
- Posts: 92
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Combine Multiple Transactions Into One
How would you recommend I force the start of a new transaction group?
-
- Premier Member
- Posts: 4889
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Combine Multiple Transactions Into One
Never really thought about it further ...333onlyhalfevil wrote: ↑Wed Jan 08, 2025 3:55 pmHow would you recommend I force the start of a new transaction group?
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
-
- Full Member
- Posts: 92
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Combine Multiple Transactions Into One
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.
-
- Premier Member
- Posts: 4889
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Combine Multiple Transactions Into One
With "all" and "one" I have too little info to help you further.333onlyhalfevil wrote: ↑Thu Jan 09, 2025 1:08 amAll but one of my scripts ... The one that is giving problems
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
-
- Premier Member
- Posts: 4889
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Combine Multiple Transactions Into One
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:
I also think that you can't stack it ....
CVH
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;
- 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
CVH
-
- Full Member
- Posts: 92
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Combine Multiple Transactions Into One
The code in the code block doesn't change anything.
Anyways, thank you very much for your help. I'll mark this one as solved.
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.