Skip to content

State

Puts the scene back after every datapoint.

Augmentations change the scene in place. Run them, and the generating step, inside with state.restoring():, and every value they changed is set back when the block ends, also when something in it raises. Nothing has to be listed or saved first: each augmentation records the values it changes, including those of augmentations inside a OneOf, Chain, Node or Modifier.

restoring

restoring() -> Iterator[None]

Sets every value changed inside the block back when it ends.

The augmentations record each value the first time they change it, and the block's end sets them back, the last change first. That covers transforms, render visibility, node and modifier inputs, material slots, camera settings and any value changed by a data path. Changes made by your own code are not recorded: make them with set to have them set back too. Blocks can be nested; an inner block sets its changes back when it ends.

Augmentations called outside a restoring() block change the scene for good.

Example
for _ in range(100):
    with state.restoring():
        objects_aug([car_1, car_2])
        lamp_aug([lamp])
        generator()

set

set(owner: Any, name: str, value: Any) -> None

Sets owner.name to value, and inside a restoring() block sets it back when the block ends.

For changes your own code makes between augmentations, e.g. a value that depends on what an augmentation did.

Parameters:

  • owner (Any) –

    the Blender struct, e.g. lamp.data.

  • name (str) –

    the attribute to set.

  • value (Any) –

    the new value.

Example
with state.restoring():
    objects_aug([car])
    if car.location.z > 1:
        state.set(lamp.data, "energy", 2000)
    generator()