I have a complicated script that does a bunch of stuff to a glyph’s shape. Is there a way to set a kind of checkpoint in the script so that undo would undo everything the script did after the checkpoint? Is this what beginUndo() is for? If so, how do I use it?
The use case is a script that has a last step of calling the Noodler filter. With 95% of glyphs it gets me the results I want, but for the other 5% I would like to undo the Noodler filtering done by the script, adjust the paths for a better result, and then manually redo the filter.
You surround all the individual steps (that are supposed to be undoable separately) with:
glyph.beginUndo()
dosomething(glyph)
glyph.endUndo()
.
If you use this, you need to wrap everything you do to the glyph. You can however have several groups.
This is not good:
dosomething(glyph)
glyph.beginUndo()
dosomething(glyph)
glyph.endUndo()
This is OK
glyph.beginUndo()
dosomething(glyph)
glyph.endUndo()
glyph.beginUndo()
dosomething(glyph)
glyph.endUndo()
1 Like
The fact that my script creates new glyphs along the way is making this confusing for me.
Here’s an outline of the script and where I’ve put the undo stuff, but doesn’t appear to be working. My goal is to be able to undo the filtering in glyphs on which the script is run and on new glyphs it creates.
for layer loop
layer.parent.beginUndo()
do stuff to layer
do other stuff to layer
layer.parent.endUndo()
if loop that creates certain variant glyphs
if loop that collects some of those glyphs
for glyph in collected glyphs loop
glyph.beginUndo()
run filter on glyphs first layer
glyph.endUndo()
else
layer.parent.beginUndo()
run filter on layer
layer.parent.endUndo()
why is the if loop that creates certain variant glyphs
inside the for layer loop
. So depending on the if loop that collects some of those glyphs
line, it seems that this collecting is done for each layer, so it might be applied too often.
1 Like
Aha, you’re right, the structure is flawed. I think I had it in my head that the script needed one overarching iteration but of course that’s not true.
But maybe I do want that iteration: if I select /n/o in text mode, I do want the script to produce /n.init, /n.medi, /n.fina, /o.init, /o.medi, and /o.fina.
It is difficult to help with such a rudimentary code. But undo wise, it looks quite right.
Maybe you make two scripts. One making the extra glyphs and one applying the filter?