ZBrushCentral

New zscript command [MergeUndo]

I was looking through some new macros that come with ZB2018 and noticed that they utilize a new command that I hadn’t ever seen before called MergeUndo. The basic gist of it seems to be that using this command after any command that creates an Undo entry will cause that command to be skipped over when undoing. This is great because it means that my scripts can be undone with a single undo rather than stepping through potentially lots of commands. however, it doesn’t seem to always work as expected. sometimes when I use it, undo will skip some commands that were done BEFORE my script ran. I can’t seem to figure it out. Anyone know more in depth how this command should best be used?

thanks!

Yes, you put it before any command that you want to be skipped when undoing. So running this code will register 6 on the Edit>UndoCounter slider but pressing Undo or Ctrl+Z will return the counter to 1.

[Loop,5,
[MergeUndo]
[ISet,Tool:Deformation:Size,10]
]

It should NOT undo anything that was done before the zscript started, so if you are seeing this behaviour please give me an example that I can test.

Thanks,

Hi Ryan,

I found the problem. The [MergeUndo] command merges the next undo with the previous undo. This means that you have to make sure that your script always has a command that creates an undo state before using MergeUndo, otherwise ZBrush will merge the undo with one prior to the script running (as you found).

So, for example, if your code has this at its start:

[If,[IsEnabled,Tool:Geometry:Higher Res],
[ISet,Tool:Geometry:SDiv,[IGetMax,Tool:Geometry:SDiv]]
]// end if

The code will only run if the model is not already at its highest subdivision level. If the model is at the highest level then nothing needs to be done and so no undo state is created. So you need to take account of this in some way, such as switching to a lower level first if necessary.