Is there a default undo operation?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Is there a default undo operation?

Post by wmayer »

No, not for GUI stuff at the moment.
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: Is there a default undo operation?

Post by lainegates »

ok, thank you, wmayer.
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: Is there a default undo operation?

Post by mea08kw »

wmayer wrote: Tue Jul 16, 2013 1:45 pm You are mixing up two concepts: the transaction framework and macro recording
1. Does a transaction starts with 'FreeCAD.ActiveDocument.openTransaction([name])' and ends with FreeCAD.ActiveDocument.commitTransaction() ?
Yes. And for convenience you can also do:

Code: Select all

FreeCAD.ActiveDocument.openTransaction("Command 1")
... # change some properties
FreeCAD.ActiveDocument.openTransaction("Command 2")
...
The second call of openTransaction automatically closes the first transaction.
2. Will commands between 2 transactions be recorded?
The recording of a command has nothing to do with the transaction framework. Since (funnily) for Python it's impossible to record the code (because we need to save a string) Yorik wrote the saveTransaction() function where he can pass a string to the interpreter and thus make it possible to record the command.
3. What kinds of command could be recorded?
If macro recording is activated and the command comes through the doCommand() function it gets recorded.

And again for the transaction framework it's currently impossible to store changes on the GUI side. So, that's why your script doesn't do for CTRL+Z. Here is a modified one:

Code: Select all

import FreeCAD , FreeCADGui , Part
from FreeCAD import Vector

obj = FreeCAD.ActiveDocument.addObject("Part::Feature", 'ABC')
v1 = Vector(1,1,0)
v2 = Vector(1,0,0)
v3 = Vector(0,0,0)
v4 = Vector(0,1,0)
l1 = Part.makeLine(v1,v2)
l2 = Part.makeLine(v1,v3)
l3 = Part.makeLine(v1,v4)

def saveTransaction(commands):
    assert isinstance(commands , list)
    FreeCAD.ActiveDocument.openTransaction('abc')
    for command in commands:
        FreeCADGui.doCommand(command)
    FreeCAD.ActiveDocument.commitTransaction()

saveTransaction(['''FreeCAD.ActiveDocument.getObject('ABC').Shape = l1'''])
saveTransaction(['''FreeCAD.ActiveDocument.getObject('ABC').Shape = l2'''])
saveTransaction(['''FreeCAD.ActiveDocument.getObject('ABC').Shape = l3'''])
Hi wmayer

Thanks for your clarification in transaction.

Generally if we save and re-open the project, the history of undo/redo is gone.

I'm wondering if we could also save the history of undo/do, in this way, undo/redo is still alive when re-opening.

Looking forward to hearing from you.

Best Regards,

Mea08kw
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Is there a default undo operation?

Post by wmayer »

I'm wondering if we could also save the history of undo/do, in this way, undo/redo is still alive when re-opening.
This would be very difficult and I doubt that this is common behaviour. If you check any text editor then the undo/redo list is also gone when closing the file.
Post Reply