Batch & Async Execution
Batch
- class dazpy.Batch(client)[source]
Bases:
objectCollect 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)
- 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
returnneeded).- Returns:
A
BatchFuturethat resolves afterexecute().- Return type:
BatchFuture
- class dazpy.BatchFuture(key)[source]
Bases:
objectPlaceholder for a single result within a
Batchexecution.Created by
Batch.add(); thevalueproperty 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/resultwith long-polling until the script completes or timeout is exceeded.- Parameters:
- Returns:
An
ExecutionResulton success.- Raises:
AsyncExecutionError – If the script fails or the request is cancelled.
TimeoutError – If timeout is exceeded before the script completes.
- Return type:
UndoGroup
- class dazpy.UndoGroup(client, label)[source]
Bases:
objectContext 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)