Batch & Async Execution

Batch

class dazpy.Batch(client)[source]

Bases: object

Collect multiple DazScript operations and execute them in a single HTTP round-trip.

Usage as a context manager (recommended):

with Batch(client) as b:
    pos_future  = b.add(["var pos = Scene.findNode('Figure').getWSPos();",
                          "var pos = [pos.x, pos.y, pos.z];"])
    name_future = b.add(["var name = Scene.findNode('Figure').getName();"])
# Both futures resolved after the `with` block
print(pos_future.value, name_future.value)

Or manually:

b = Batch(client)
f = b.add(["var x = 42;"])
b.execute()
print(f.value)
Parameters:

client (DazClient) – The DazClient to use.

add(lines)[source]

Queue a list of DazScript lines to be included in the batch.

The last line in lines should assign the desired result to a variable named after the key that will be referenced internally.

Parameters:

lines (list[str]) – DazScript source lines (no return needed).

Returns:

A BatchFuture that resolves after execute().

Return type:

BatchFuture

execute()[source]

Execute all queued operations in a single HTTP request and resolve all futures.

BatchFuture

class dazpy.BatchFuture(key)[source]

Bases: object

Placeholder for a single result within a Batch execution.

Created by Batch.add(); the value property blocks until the batch has been executed.

property value: object

The result value.

Raises:

RuntimeError – If Batch.execute() has not been called yet.

execute_long

dazpy.execute_long(client, script, args=None, timeout=120.0, poll_interval=0.5)[source]

Execute a potentially long-running script via the async endpoint with polling.

Submits script asynchronously, then polls /requests/:id/result with long-polling until the script completes or timeout is exceeded.

Parameters:
  • client (DazClient) – The DazClient to use.

  • script (str) – DazScript source code.

  • args (object) – Optional argument passed to the script.

  • timeout (float) – Maximum total wall-clock seconds to wait.

  • poll_interval (float) – Seconds to sleep between short polls when the server returns before the long-poll timeout.

Returns:

An ExecutionResult on success.

Raises:
Return type:

ExecutionResult

UndoGroup

class dazpy.UndoGroup(client, label)[source]

Bases: object

Context manager that groups DAZ Studio operations into a single undo step.

On successful exit the changes are committed with acceptUndo(label). If an exception propagates, cancelUndo() is called instead.

Obtain via DazScene.undo() rather than constructing directly:

with scene.undo("Rotate arm"):
    skel.find_bone("r_forearm").set_local_rotation(0, 0, 45)
Parameters:
  • client (DazClient) – The DazClient to use.

  • label (str) – The label shown in DAZ Studio’s Edit > Undo menu.