Undo

Creating an undo point

When modifying elements, textures, animations or anything else about the model, the changes need to be registered to the Undo system. This will a) create an Undo point to allow the user to undo the changes and b) synchronize the model to other users in an Edit Session. This can be achieved using Undo.initEdit and finishEdit.

Undo.initEdit( aspects )

Initializes an edit. Call this when you are about to do an edit, before changing anything.

  • aspects. Which aspects of the model to save. See #Aspects

Undo.finishEdit( edit_name[, aspects] )

Wraps up and saves an edit. Call this function after doing your edit.

  • action_name Name of the performed edit.
  • aspects Optional. If the set of aspects you are editing has changed, provide the changed aspects.

Aspects

Aspects are used to tell Blockbench which parts of the model to save in an undo point. All aspects are within one aspects object. When adding or removing elements, textures etc., make sure the objects in question are stated in the first but not in the second aspects, or vice versa.

AspectDescriptionExample
selectionIf true, the element and group selection will be saved{selection: true}
elementsArray of all elements (cubes and locators) to save.{elements: [cube1, cube2, locator]}
outlinerIf true, the complete outliner structure will be saved. This includes group data like names etc.{outliner: true}
groupA single group.{group: Group.selected}
texturesAn array of textures.{textures: [texture]}
bitmapIf true, the content of the listed textures will be saved.{textures: [texture], bitmap: true}
uv_modeWhen true, saves the current UV mode and project resolution settings.{uv_mode: true}
animationsArray of animations{animations: [Animator.selected]}
keyframesArray of animation keyframes{keyframes: [keyframe]}
display_slotsArray of display slot ids{display_slots: ['thirdperson_righthand', 'head']}
uv_onlyIf true, only UV and face information of cubes will be saved.{elements. Cube.selected, uv_only: true}

Example

Undo.initEdit({elements: []});

let new_cube = new Cube({name: 'kevin'}).init();
let other_cube = new Cube({name: 'lars'}).init();

Undo.finishEdit('add new cubes', {elements: [new_cube, other_cube]});