Skip to content

Transactions and undo

Project operations produce versioned history. A standalone operation normally creates one undo entry. Group related operations in a transaction when users should undo them together.

Temporary scene shapes and camera actions do not become project history.

Transaction

Submit related project operations through a transaction, then commit. One undo removes the whole group. These examples assume a connected client.

import spatialengine

with spatialengine.connect() as client:
    with spatialengine.Transaction(client, mode="Private") as txn:
        parent = txn.submit(client.project.object.spawn)
        child = txn.submit(client.project.object.spawn)
        txn.submit(client.project.object.set_parent, node=child, parent=parent)
        txn.commit()
    client.project.undo()

Leaving the context without committing cancels it. An exception also triggers cancellation.

Shared and private transactions

A shared transaction is the default. It includes operations submitted while it is open, including untagged operations from other clients.

A private transaction accepts only operations tagged with its ID. Use txn.submit to tag calls. The engine rejects other operations while it is open.

Choose the mode deliberately when more than one client controls an engine.

Completion and leases

Await every submitted operation before committing. The engine rejects operations that are still in flight when the transaction ends.

SDK transaction helpers renew a lease while the transaction is active. If the client disappears, the engine cancels the transaction when the lease expires. The default lease is 60 seconds.

An operation completes when its changes are applied. Commit completes when the transaction is durable.

Saving and collaboration

Undo history does not replace saving a project. Use the local project API for disk persistence or the remote project API for SpatialDrive. Shared project access is controlled by the server.

Client integration.