On 26/02/2013 at 12:57, xxxxxxxx wrote:
I´m trying to make proper use of undo, but it´s very confusing, SDK not being a big help here...
I´ve got a dialogue with a number field (IDC_POS) controlling the position of an object.
The GeDialog.Command looks basically like this:
def Command(self, id, msg) :
doc = c4d.documents.GetActiveDocument()
obj = doc.GetActiveObject()
doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
# Rightclick Reset X to 0
if id == IDC_POS and "Rightclick" == True:
......
# Value Change to Object Position
if id == IDC_POS:
if obj:
x_value = self.GetReal(IDC_POS)
pos = obj.GetAbsPos()
pos.x = x_value
obj.SetAbsPos(pos)
c4d.DrawViews()
return True
doc.EndUndo()
Undo works for rightclick on the number arrows, setting pos.x to 0.
But if I drag the value with the mouse-button pressed, undo is repeating every little step, instead of the initial value. Using AddUndo within the if methods doesn´t help. Also it takes two undos to get going, same when I type an value in here.
If somebody would have a solution, or maybe a better explanation on the undo stuff, you´d make me very happy ;-)
I don´t really get the definition of Start and Add undo:
StartUndo seems like a general toggle for undo support, but it still matters where exactly you put it? So it starts storing everything from here on? End Undo stops that storing...
AddUndo basically tells you which object and undotype you want to perform, while an Undo does recover the objects state within the code at that AddUndo Command?
Are there cases you use multiple Start/End Undos?